您好我正在使用TPH继承来建立类似的可配置项。我的TPH模型是:
public class baseConfigItem
{
public int ID {get; set;}
public string ExternalText {get; set;}
public string InternalText { get; set; }
public bool Active { get; set; }
public string Group { get; set; }
public int SortOrder { get; set; }
public statusDef status { get; set; }
public virtual ICollection<Order> Orders{get;set;}
public baseConfigItem()
{
this.Orders= new List<Order>();
}
}
public class DoorTypes:baseConfigItem{public DoorTypes():base(){}}
public class WindowType : baseConfigItem { public WindowType():base(){}}
public class WallType : baseConfigItem { public WallType():base(){}}
public class RoofType : baseConfigItem { public RoofType():base(){}}
public class RoofSize : baseConfigItem { public RoofSize():base(){}}
public class DoorSize : baseConfigItem { public DoorSize():base(){}}
public class GardenSize : baseConfigItem { public GardenSize():base(){}}
然后我需要与具有订单实体的子实体创建多对多和一对多/多对一的关系:
public class Order
{
public int ID {get; set;}
public virtual ICollection<WindowType> WindowTypes {get; set;}
public virtual ICollection<WallType> WallTypes {get; set;}
public virtual ICollection<RoofType> RoofTypes {get; set;}
public RoofSize RoofSize {get; set;}
public DoorSize DoorSize {get; set;}
public GardenSize GardenSize {get; set;}
}
然而,这并没有为RoofTypes,WallTypes等产生多对多的关系......我假设公共虚拟ICollection Orders {get; set;}将被继承。我如何能够建立具有多对多和一对多关系的上述继承类?
答案 0 :(得分:0)
我试过你的模特。它对我有用,没有一个改变(好吧,这不完全正确,我改变了#34; StatusDef&#34; bool,但这没有任何区别。)和&#34; poof&#34; - 我有所有的关系工作。您需要做的就是编译并运行一次项目。这将成为所有表格。然后去检查你的SQL服务器。
祝你好运。