开发者

FluentNHibernate Mixing Fluent and Auto Mappings

开发者 https://www.devze.com 2023-03-24 21:54 出处:网络
Is there a clean way to mix fluent mappings wit开发者_如何学编程h automappings? Ideally, I\'d like to say \"if I don\'t have a ClassMap for a domain object, then automap it\".Is there a recommended ap

Is there a clean way to mix fluent mappings wit开发者_如何学编程h automappings? Ideally, I'd like to say "if I don't have a ClassMap for a domain object, then automap it". Is there a recommended approach? I'd rather not use attributes on my business objects that are data access related (ex: [UseAutoMapping]).


Yes - check out IAutoMappingOverride

Basically, any mappings which override the Automapping behaviour need to implement this interface.

e.g.

public class MyClassMap : IAutoMappingOverride<MyClass>
{
    public void Override(AutoMapping<MyClass> mapping)
    {
        mapping.IgnoreProperty(host => host.HostName);
        mapping.Table("BobsHardware");
    }
}
0

精彩评论

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