根据子类型映射到不同的视图 [英] Mapping to a different view based on child type

查看:144
本文介绍了根据子类型映射到不同的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个情况,我有共同的基础类型,但我需要映射到基于子类型的不同视图。

它看起来像我可以使用一个通用的映射类来处理继承

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



但我怎样才能有条件地映射到一个不同的基于子类型的视图?我看到一个EntityType属性,但它表示它的过时,并将在下一个版本中被私有。

作为一个例子,我有一个ContactInfo的基类是标准的联系类型但值来自不同的地方,取决于联系类型,这我会通过SQL视图处理。

解决方案

使用任何映射引用的实体来自不同的表

  class ContactInfo 
{
public virtual long Id {get ;组; }
public virtual ContactDetails Details {get;组; }
}
$ b public ContactInfoMap
{
...
ReferencesAny(x => x.Details)
.EntityIdentifierColumn( (contact)
.IdentityType< long>()
.AddMetaValue< FooContactDetails>(1)
.AddMetaValue< BarContactDetails> 4\" );
}


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.

解决方案

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");
}

这篇关于根据子类型映射到不同的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆