views:

177

answers:

1

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


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

vs

public class PostMap : IAutoMappingOverride<Post>
{
    public void Override(AutoMapping<Post> mapping) 
    {
        ...
    }
}
+1  A: 

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:

Erik Öjebo

related questions