我不知道是否可以将子类属性映射到基类表。说我有两个班(缩短):EF代码优先 - 将子类属性映射到基类表
public abstract class User
{
[Key]
public int UserId { get; set; }
public string Username { get; set; }
// other properties...
}
和
public class Customer : User
{
public int ShopId { get; set; }
public virtual Shop Shop { get; set; }
// other properties...
}
我使用TPT(每种类型的表)继承(这意味着两个表 - 用户和客户)。由于某些原因,我希望在用户表中有ShopId
属性,但在Customer表中有Customer
类中的所有其他属性。这甚至可能吗?
在User表中有ShopId列允许我们在用户名和ShopId上创建唯一索引(应用程序是多租户的,所以我们不需要全球唯一的用户名,只有商店级的唯一用户名)。
小号o为什么不能将shopId放入用户? ef不会为摘要创建表格。 –
这是使用TPT时。此外,我不想从'用户'和'商店'有任何关系。 'User'与'Shop'无关,只有'Customer'。 – MrHenkey