开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜