Fluent automappings override single property
I'm using Fluent Nhibernate with AutoMappings. It provides ability to override any mapped property in following way:
public class CommunityMap : IAutoMappingOverride<Community>
{
public void Override(AutoMapping<Community> mapping)
{
mapping.Map(x => x.Description).Length(5000);
mapping.Cache.ReadWrite();
}
}
This class changes not only Length
property of Description
column, but also it changes column name in 开发者_StackOverflowmappings. The same goes to HasMany
and others. For example I want to disable lazy loading for particular collection, but leave all other attributes as set by automappings. Is it possible with FNH?
Yes, it's possible.
public class ContractMappingOverride : IAutoMappingOverride<Contract>
{
public void Override(AutoMapping<Contract> mapping)
{
mapping.HasMany(x => x.Details).Access.CamelCaseField(Prefix.Underscore).Cascade.AllDeleteOrphan();
}
}
I just copied that from my production code.
精彩评论