开发者

FluentNHibernate - ClassMap vs IAutoMappingOverride

开发者 https://www.devze.com 2022-12-27 21:22 出处:网络
In FluentNHibernate when should I use ClassMap and when IAutoMappingOverride<Entity> for my EntityMap classes.

In FluentNHibernate when should I use ClassMap and when IAutoMappingOverride<Entity> for my EntityMap classes.

public class PostMap : ClassMap<Post>
{
    public PostMap()
    {
        ...
    }
}

vs

pub开发者_运维知识库lic class PostMap : IAutoMappingOverride<Post>
{
    public void Override(AutoMapping<Post> mapping) 
    {
        ...
    }
}


ClassMaps are used when manually mapping your entities. In that case you create a separate ClassMap for every entity which specifies how that entity is mapped to the database.

IAutoMappingOverrides are used when mapping your entities with AutoMapping. When using AutoMapping Fluent NHibernate tries to automatically figure out how the entities should be mapped to the database, but sometimes the automatically generated mappings are not quite what you wanted, so you have to override the parts that need tweaking. In that case you create a mapping override for each entity who's auto mapping needs to be overridden, and override only those parts.

More info can be found at the Fluent NHibernate wiki:

  • AutoMapping
  • Fluent Mapping (ClassMaps)
0

精彩评论

暂无评论...
验证码 换一张
取 消