我正在使用Fluent Nhibernate(很高兴)但在映射某些实体方面遇到了一些麻烦:
public enum AdverticeType { None,Image,Flash,Script}
public class Advertice
{
public virtual int ID { get;set;}
public virtual string Name { get;set;}
public virtual AdverticeType AdverticeType { get;set;}
}
public class ImageAdvertice : Advertice
{
public virtual int ID { get;set;}
public virtual string Path { get;set;}
public virtual string URL { get;set;}
}
public class ScriptAdvertice : Advertice
{
public virtual int ID { get;set;}
public virtual string Code { get;set;}
}
如何映射到实体,以便ScriptAdvertice中的ID由广告中的ID生成。
答案 0 :(得分:0)
使用Advertice
使用ClassMap
,使用ImageAdvertice
ScriptAdvertice
和SubclassMap
映射public class AdverticeMap : ClassMap<Advertice>
{
public AdverticeMap()
{
Id(x => x.ID);
}
}
public class ImageAdverticeMap : SubclassMap<ImageAdvertice>
{
public ImageAdverticeMap()
{}
}
public class ScriptAdverticeMap : SubclassMap<ScriptAdvertice>
{
public ScriptAdverticeMap()
{}
}
。
e.g。
{{1}}