NHibernate View in queryover returns duplicate records

I seem to have a strange problem with one of my database views that I have mapped to NHibernate. I get duplicate entries for one of the views that I have mapped. I have the following view objects

                      WorkDetailView
                       /          \
                      /            \
                     /              \
                    /                \
          PickWorkDetailView    PutWorkDetailView

Each object represents a different view in the database, but both PickWorkDetailViewand PutWorkDetailViewinherit from WorkDetailView, because they share many of the same fields.

If I run the following code snippet, I get 2 results, but if I run the actual database view in SQL Management Studio, I get 1 result.

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

The interesting part is that when I look through all the elements in the collection workListabove, I see one object WorkDetailViewand one object PickWorkDetailView. Also, if I look at the queries that NHibernate launches, you select from all three views (WorkDetailView, PickWorkDetailView and PutWorkDetailView). That doesn't sound right. I can publish xml mappings or my current mappings if necessary.

+3
source share
1 answer

NHibernate supports polymorphic queries. So, when you request this base class, it will search for all objects derived from this class.

You can control this behavior with the polymorphism attribute in class mapping.

, , , , . , , , , , , <class> <subclass> <joined-subclass>. polymorphism="implicit". , ( "" , ).

polymorphism="explicit" 3 .

+6

All Articles