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

Athina
  • 533
  • 5
  • 20
  • It's always a good idea to post the code that is giving you trouble. Can you do that? – csano May 09 '11 at 19:35
  • 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. – Tomas May 10 '11 at 10:35
  • 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. – Athina May 10 '11 at 10:48
  • 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? – Tomas May 11 '11 at 06:28

2 Answers2

54

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>().

cremor
  • 6,669
  • 1
  • 29
  • 72
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();
}
Tomas
  • 3,573
  • 2
  • 20
  • 25