Search code examples
linqnhibernatelinq-to-nhibernatenhibernate-projections

cannot project entities in Linq 2 NHibernate


I'm working with NHibernate 2 in a .Net project and I'm using the Linq2NHibernate provider. This simple query

var result = from d in session.Linq<Document>()
where d.CreationYear == 2010
select d.ChildEntity).ToList();

throws an exception telling me that is impossible to cast ChildEntity type do Document type. Why is that? I also tried to translate it in query methods, having

session.Linq<Document>()
   .where(d=>d.CreationYear == 2010)
   .select(d=>d.ChildEntity)
   .ToList();

Isn't the select method supposed to project an IQueryble into a IQueryble, beeing TResult!=T ?


Solution

  • The old Linq provider is extremely limited and has been unmaintained for several years.

    I suggest that you upgrade to the latest stable NHibernate (3.2), which has a much better (and integrated) Linq provider.