为什么只创建了一个table?

Why is only one table created?

我对多个表使用一个模型,但是当我创建表时,只创建了其中一个。为什么会这样,可以更改吗?

  public DbSet<ShopItemProperty_Model> Champagne_TBL { get; set; }
    public DbSet<ShopItemProperty_Model> Gin_TBL { get; set; }
    public DbSet<ShopItemProperty_Model> Rum_TBL { get; set; }
    public DbSet<ShopItemProperty_Model> SparklyWine_TBL { get; set; }
    public DbSet<ShopItemProperty_Model> Whisky_TBL { get; set; }
    public DbSet<ShopItemProperty_Model> WhiteWine_TBL { get; set; }
    public DbSet<ShopItemProperty_Model> RedWine_TBL { get; set; }
    public DbSet<ShopItemProperty_Model> Wodka_TBL { get; set; }

EfCore 根据您的类型创建 table,所以 如果你必须这样做,你可以将一个模型作为抽象 class 并定义另一个继承自该模型的模型。

此外,我不得不说这个数据库设计可能会更好,我不知道你的业务,但最简单的方法是创建一个 table 带有特殊描述符,如枚举

public abstract class ShopItemProperty_Model
{
    public int Id { get; set; }
    /* Other fields */
}

[Table("Gin_TBL")]
public class Gin_TBL : ShopItemProperty_Model
{
}

[Table("Rum_TBL")]
public class Rum_TBL : ShopItemProperty_Model
{
}

[Table("SparklyWine_TBL")]
public class SparklyWine_TBL : ShopItemProperty_Model
{
}

[Table("Whisky_TBL")]
public class Whisky_TBL : ShopItemProperty_Model
{
}

[Table("WhiteWine_TBL")]
public class WhiteWine_TBL : ShopItemProperty_Model
{
}

[Table("RedWine_TBL")]
public class RedWine_TBL : ShopItemProperty_Model
{
}

[Table("Wodka_TBL")]
public class Wodka_TBL : ShopItemProperty_Model
{
}