如何在Fluent NHibernate中创建基本实体和基类映射

时间:2016-04-10 17:16:47

标签: c# nhibernate orm fluent-nhibernate

我在所有表格中都有共同的列“Id,IsActive,CreateDate”。现在我想在我的基本实体中移动“Id,IsActive,CreateDate”,并且还想创建基本映射。如何在Fluent NHibernate中实现这一目标?

1 个答案:

答案 0 :(得分:2)

您可以像这样创建基本映射:

public class BaseMap<T> : ClassMap<T> where T : Address
{
    public BaseMap()
    {
        Id(x => x.Id);
        Map(x => x.IsActive);
        Map(x => x.CreateDate);
    }
}

public class SomeEntityMap: BaseMap<SomeEntity>
{
    public CustomerAddressMap()
    {
        Table("SomeTable");
        Map(x => x.SomeProperty);
    }
}

public class Entity
{
   public virtual Guid Id { get; set; }
   public virtual bool IsActive { get; set; }
   public virtual DateTime CreateDate { get; set; }
}

public class SomeEntity : Entity
{
   public virtual string SomeProperty { get; set; }
}