Hi there,
I am really struggling to create a Criteria based query in NHibernate.
In simplistic model of my domain I have:
Order (maps to table Orders) object
Order has a one-to-many relationship with OrderItem (maps to OrderItems table) and is mapped as a bag property: Items.
Each OrderItems has a one-to-many relationship with Seller (maps to Sellers) and a mapped proerty of Owner
I need to write a query that says "Give me all the Orders that contain items sold by :SellerID"
Depending on user inputs I want to then add further criteria such as a date range.
This is what I have:
Code:
ICriteria crit = session.CreateCriteria(typeof(Order));
crit.CreateCriteria("Items").CreateCriteria("Owner").Add(Expression.IdEq(sellerID));
...
However this query is highly inefficient, and often timeout my sql server db locally.
Can anyone help?
Many thanks for your help in answering what is surely a simple question.
Regards, Richard