开发者

Fluent automappings override single property

开发者 https://www.devze.com 2023-03-03 08:03 出处:网络
I\'m using Fluent Nhibernate with AutoMappings. It provides ability to override any mapped property in following way:

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

精彩评论

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