Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with linq query

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

like image 875
Athina Avatar asked May 09 '11 17:05

Athina


People also ask

Is LINQ to SQL obsolete?

"As long as LINQ to SQL lives under Entity Framework, it's dead.

Is LINQ better than SQL?

More importantly: when it comes to querying databases, LINQ is in most cases a significantly more productive querying language than SQL. Compared to SQL, LINQ is simpler, tidier, and higher-level.

Is LINQ good for performance?

LINQ syntax is typically less efficient than a foreach loop. It's good to be aware of any performance tradeoff that might occur when you use LINQ to improve the readability of your code. And if you'd like to measure the performance difference, you can use a tool like BenchmarkDotNet to do so.


1 Answers

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

like image 141
cremor Avatar answered Nov 08 '22 22:11

cremor