Problem with linq query
Asked Answered
A

2

30

I'm trying to use linq to NHibernate (with Fluent NHibernate) but I have problems with linq query. Everytime I try to execute it I get this message :

"Method 'get_IsReadOnlyInitialized' in type 'NHibernate.Linq.Util.DetachedCriteriaAdapter' from assembly 'NHibernate.Linq, Version=1.1.0.1001, Culture=neutral, PublicKeyToken=null' does not have an implementation."

Does anybody know how to fix this problem? I tried with solution form this page with model context but it didn't help.

This is the code:

using(var session = NHibernateHelper.OpenSession())   
{   
var informations = (from i in  session<Information>() where i.Text=="some text" select  i).ToList();   
}

Everything is fine if I don't use the where part but if I use it I get this error. I think that the problem is in NHibernate.Linq.dll

Asynchronism answered 9/5, 2011 at 17:56 Comment(4)
It's always a good idea to post the code that is giving you trouble. Can you do that?Xylograph
is this using Nhibernate 2 and NHibernate.Linq project? Have you tried to test the same in Nhibernate 3, If I remember correctly Linq support should be build in.Lashanda
No, I have NHibernate 3.1.0.4000, FluentNHibernate 1.2.0.712 and NHibernate.Linq 1.0. It's not built in. I had to add it independently.Asynchronism
I see. Is this integrated in an existing solution, or a new project? Have you tried to reproduce the same query using the native Nhibernate ICriteria? If this does not help, then can you either post the relevant mappings, or even better, a full test project with code and db schema?Lashanda
C
53

You should not use NHibernate.Linq.dll with NHibernate 3.0! NHibernate 3.0 has Linq included (a by far better version than the old extension dll), you just need to add using NHibernate.Linq; and use session.Query<T>() instead of session.Linq<T>().

Chaliapin answered 11/5, 2011 at 9:5 Comment(1)
what do you use instead of QueryOptions, and NHibernateQueryProvider?Memorabilia
L
0

as far as I can see you are not comparing, but assigning the Text.

Should it not be == in stead of =:

using(var session = NHibernateHelper.OpenSession()) {
var informations = (from i in session<Information>() where i.Text=="some text" select i).ToList();
}
Lashanda answered 10/5, 2011 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.