English 中文(简体)
NHibernate - How to fetch conditions data from database using hbm filemap
原标题:NHibernate - How to fetch conditional data from database using hbm file mapping

目前,我正在使用“many-to-one >中藏书的元件,从数据库中挑选数据标象如下。

<property name="ContactId" length="4" />
<many-to-one
    name="DefaultContact"
    column="ContactId"
    class="Models.Contact"
    update="false"
    insert="false"/>

这份法典正在妥善收集数据,但现在我需要有条件地收集数据,就像在黑手档案中具有以下特性和单体元素。

<property name="ParentId" length="4" />
<property name="ParentType" length="4" />
<many-to-one
        name="ContactParent"
        column="???????? ParentId which could be CustomerId or ProspectId or LeadId according to Parent Type ????????"
        class="???????? Models.Customer or Models.Prospect or Models.Lead - according to Parent Type ????????"
        update="false"
        insert="false"/>

And I have to fetch the data according to value in "Parent Type" property, which means I need to set class attribute of "many-to-one" element dynamically according to "Parent Type" property.

因此,现在,我怎么能以许多对一的内容或其他方式取得预期成果?

预付款。

问题回答

http://nhibernate.info/doc/nh/en/index.html

它最接近你们希望做些什么。

我可以想出两种办法处理这一问题。

  1. Don t包括该模式中的接触者,使用单独的方法从父母Type和父母Id那里检索。

  2. 选择所有三个家长类型作为私人成员,并归还在公有财产中不作废的人。

备选办法1将是我的第一个选择。





相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....