English 中文(简体)
查询中的 Whenate View 返回重复记录
原标题:NHibernate View in queryover returns duplicate records

我用Nhibertenate绘制的数据库视图之一似乎有一个奇怪的问题。 我所绘制的视图之一有重复的记录。 我有以下的视图对象:

                      WorkDetailView
                       /          
                      /            
                     /              
                    /                
          PickWorkDetailView    PutWorkDetailView

每个对象在数据库中代表不同的视图,但 PickWorkDetailView PutWorkDetailView 两者都继承了 WorkDetailView ,因为它们共享许多相同的字段。

如果我在SQL管理工作室 运行下面的代码,我得到2个结果 但如果我运行SQL管理工作室的数据库视图,我得到1个结果。

List<WorkDetailView> workList = session.QueryOver<WorkDetailView>()
                                       .List<WorkDetailView>().ToList();

有趣的部分是,当我查看以上 workList 收藏中的所有项目时, 我可以看到一个 WorkDetailView 对象和一个 pickWorkDetailView 对象。 另外, 如果我查看Nhebertnate 正在运行查询, 它会从所有 3 个视图( WorkDetailView, PickWorkDetailView, PutWorkDetailView) 中选择问题。 这听起来根本不正确。 如果需要, 我可以张贴 xml 映射或我的流利映射映射 。

最佳回答

Nhenet 支持多形态查询。 所以, 当您询问该基类时, 它会查找从该类中衍生出来的所有对象 。

您可以在班级绘图中用 " http://www.nhforge.org/doc/nh/en/index.html#mapping- declaration-class" rel="notfollow noreferrer" >polyformism 属性 来控制这种行为。

Implicit polymorphism means that instances of the class will be returned by a query that names any superclass or implemented interface or the class and that instances of any subclass of the class will be returned by a query that names the class itself. Explicit polymorphism means that class instances will be returned only be queries that explicitly name that class and that queries that name the class will return only instances of subclasses mapped inside this <class> declaration as a <subclass> or <joined-subclass>. For most purposes the default, polymorphism="implicit", is appropriate. Explicit polymorphism is useful when two different classes are mapped to the same table (this allows a "lightweight" class that contains a subset of the table columns).

在您的示例中, 您可以在所有 3 个映射中设置 < code>polydorphansism=" explicate" 。

问题回答

暂无回答




相关问题
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 ) ....

热门标签