为什么我的列数会增加一倍,如图所示:
如何将此列合并为一列而不是两列?
public class User
{
[Key]
public long id { get; set; }
}
public class Woman : User
{
public Woman()
{
s = new SharedManWoman();
Clone = new Clone.CWoman();
}
public Clone.CWoman Clone { get; set; }
public SharedManWoman s { get; set; }
}
public class Man : User
{
public Man()
{
s = new SharedManWoman();
Clone = new Clone.CMan();
}
public Clone.CMan Clone { get; set; }
public SharedManWoman s { get; set; }
}
public class SharedManWoman
{
[Key]
public long tableId { get; set; }
}
public class CUser
{
[Key]
public long id { get; set; }
}
public class CWoman : CUser {}
public class CMan : CUser {}
答案 0 :(得分:0)
这两个都是在单独的派生类中定义的,因为它们是导航属性,所以它们为每个派生出一个外键:
public Clone.CWoman Clone { get; set; }
public Clone.CMan Clone { get; set; }
你可以将它们移到基类而取消CWoman / CMan,而不是使它成为CUser类型:
public class User
{
[Key]
public long id { get; set; }
public Clone.CUser Clone { get; set; }
}
那应该摆脱其中一个重复的FK,但不确定这个解决方案是否适合你想要完成的任务。