3
我有以下基類。流利的NHibernate的自動映射基類覆蓋
public abstract class BaseEntity
{
public virtual long Id { get; set; }
public virtual DateTime CreateDate { get; set; }
public virtual DateTime? UpdateDate { get; set; }
public virtual bool IsDeleted { get; set; }
public virtual string CreatedBy { get; set; }
}
它是所有實體的基類。
例如,
public class Task : BaseEntity
{
public virtual string Name {get;set;}
}
我有一個初始化,
public class Initializer
{
public static AutoPersistenceModel MapEntities()
{
var p = AutoMap
.AssemblyOf<User>(new MyDefaultAutomappingConfiguration())
.IgnoreBase<BaseEntity>()
.UseOverridesFromAssemblyOf<Initializer>()
.Override<BaseEntity>(map =>
{
map.Map(b => b.CreateDate).Not.Nullable().Not.Update();
map.Map(b => b.CreatedBy).Not.Nullable().Length(100);
map.Map(b => b.ModifiedBy).Length(100);
map.Map(b => b.DeletedBy).Length(100);
map.Map(b => b.IsDeleted).Not.Nullable().Default("0");
});
return p;
}
}
當然在數據庫中,並且 - CREATEDATE是日期時間,空值和CreatedBy數據類型爲nvarchar(255)。
如何配置此AutoMapper以獲取從基類到所有子類的映射?
它的工作原理。謝謝 :) – 2011-06-02 09:29:00