I have the following base class.
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; }
}
And this is the base class for all objects.
For instance,
public class Task : BaseEntity
{
public virtual string Name {get;set;}
}
I have an initializer,
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;
}
}
And, of course, in the database - CreateDate - it is datetime, null and CreatedBy - nvarchar (255).
How can I configure this AutoMapper to get these mappings from the base class to all child classes?
source
share