0
我試圖映射這個類,結構:NHibernate的映射
public abstract class Entity
{
public virtual Guid Id {get;set;}
public virtual int Version {get;set;}
}
public class Parent: Entity
{
public virtual string ParentName {get;set;}
...
}
public class Child : Parent
{
public virtual string DisplayName {get;set;}
...
}
我按照慣例做測繪與製圖混合通過這樣的代碼:
public class ChildMappingOverride: UnionSubclassMapping<Child>
{
}
public class NHibernateMapping
{
public void MapDomain()
{
ConventionModelMapper mapper = new ConventionModelMapper();
Type baseEntityType = typeof(Entity);
mapper.IsEntity((t, declared) => (baseEntityType.IsAssignableFrom(t) && baseEntityType != t) && !t.IsInterface);
mapper.IsRootEntity((t, declared) => baseEntityType.Equals(t.BaseType));
mapper.Class<Entity>(map =>
{
map.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
map.Version(x => x.Version, m =>
{
m.Column("Version");
m.Generated(VersionGeneration.Never);
m.UnsavedValue(0);
m.Insert(true);
m.Type(new Int32Type());
m.Access(Accessor.Property);
});
});
mapper.AddMapping<ChildMappingOverride>();
}
}
好了,現在當nhibernate創建數據庫模式時,我得到2個表而不是隻有一個: Nhibernate創建的表:父和子。 我希望它只創建具有所有字段的表的子級:Id,Version,ParentName,DisplayName。
我該怎麼做? 請幫忙