Problem with linq query

送分小仙女□ 提交于 2019-12-09 05:02:29

问题


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


回答1:


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




回答2:


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();
}


来源:https://stackoverflow.com/questions/5940631/problem-with-linq-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!