Mapping to a different view based on child type

做~自己de王妃 提交于 2020-01-17 04:27:10

问题


So i have a situation where i have common base type but i need to map to a different view based on the child type.

It looks like i can use a generic mapping class to handle the inheritance

http://geekswithblogs.net/nharrison/archive/2010/07/09/inheriting-a-class-map-in-fluent-nhibernate.aspx

But how can i conditionally map to a different view based on the child type? I see an EntityType property but it says its obsolete and will be made private in the next version.

As an example i have a base class of ContactInfo is standard between contact types but the values come from different places depending on the contact type, this I'll handle through the sql view.


回答1:


using any mapping the referenced entity comes from a different table

class ContactInfo
{
    public virtual long Id { get; set; }
    public virtual ContactDetails Details { get; set; }
}

public ContactInfoMap
{
    ...
    ReferencesAny(x => x.Details)
        .EntityIdentifierColumn("details_id")
        .EntityTypeColumn("contactType")
        .IdentityType<long>()
        .AddMetaValue<FooContactDetails>("1")
        .AddMetaValue<BarContactDetails>("4");
}


来源:https://stackoverflow.com/questions/13003025/mapping-to-a-different-view-based-on-child-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!