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)
{
...
}
}
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With