Hello i've already performed an extensive search on the forums and by the search engines. This is not a bug with nhibernate but a problem on how to implement a particular query.
Hibernate version: 1.2.1.4000
Name and version of the database you are using: SQLite Ado.Net (latest, version: 1.0.60.0)
Code between sessionFactory.openSession() and session.close():
I'd like to know that.
My scenario is as follows, there is a customer order relation, for this i use a list property with the following mapping definition.
Code:
class Customer {
[NHibernate.Mapping.Attributes.List(0,
Name = "AssociatedOrders",
Table = "MM_Customer_Order",
Lazy = false,
Cascade = NHibernate.Mapping.Attributes.CascadeStyle.SaveUpdate,
[NHibernate.Mapping.Attributes.Key(1, Column = "Id_Customer")]
[NHibernate.Mapping.Attributes.Index(2, Column = "Ordering_Index")]
[NHibernate.Mapping.Attributes.ManyToMany(3, Column = "Id_Order", Class = "MyTest.Order, MyTest",
Lazy = NHibernate.Mapping.Attributes.RestrictedLaziness.False)]
public virtual IList<Order> AssociatedOrders
{
get;set;
}
}
So nhibernate uses three tables for this: Customers, Orders, and MM_Customer_Order reflecting the relation of both with an additional column "Ordering_Index" determining the sequence.
In my model the following may be true:
An Order item may be associated to several customers.
So to my question: how does a query look like that selects all customers having a particular order item contained in AssociatedOrders?
If i'd select all customers
Code:
var query = from customer in session.Linq<Customer>()
select customer;
i could scan through all via foreach to find the particular orders, which is not what i want.
A query like
Code:
var query = from customer in session.Linq<Customer>()
from o in session.Linq<Order>()
where customer.AssociatedOrders.Contains(order)
select customer;
resultSet = query.ToList();
results in a null pointer exception, probably since the collection is not yet initialized;
Code:
bei NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetWholeAssociationPath(Subcriteria subcriteria)
bei NHibernate.Loader.Criteria.CriteriaQueryTranslator.CreateAssociationPathCriteriaMap()
bei NHibernate.Loader.Criteria.CriteriaQueryTranslator..ctor(ISessionFactoryImplementor factory, CriteriaImpl criteria, Type rootEntityName, String rootSQLAlias)
bei NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, Type rootEntityName, IDictionary enabledFilters)
bei NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results)
bei NHibernate.Impl.SessionImpl.Find[T](CriteriaImpl criteria)
bei NHibernate.Impl.CriteriaImpl.List[T]()
bei NHibernate.Linq.NHibernateLinqQuery`1.get_Result()
bei NHibernate.Linq.NHibernateLinqQuery`1.GetEnumerator()
bei System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
bei System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
bei DetermineCustomersHavingOrder(Order order, ISession session)
[..]
Is there a possibility to create a linq expression tree that is able to generate an sql-query which performs the set operations on the database side, like one would expect?
I'm really looking forward for your kind answers,
thanks in advance,
Klaus