[英]Linq To nHibernate Method Not Found
Code: 码:
public IEnumerable<CalendarItem> GetCalendarItems(DateTime? startDate = new DateTime?(), DateTime? endDate = new DateTime?())
{
if (startDate.HasValue && endDate.HasValue)
{
var items = session.Linq<CalendarItem>()
.Where(x => x.EventDate >= startDate.Value && x.EventDate <= endDate)
.ToList<CalendarItem>(); //Error Here
return items;
}
//var items = session.QueryOver().OrderBy(x => x.EventDate);
return session.CreateCriteria<CalendarItem>().List<CalendarItem>().OrderByDescending(x => x.EventDate);
}
Exception 例外
Method not found: 'System.Collections.IDictionary NHibernate.ISessionFactory.GetAllClassMetadata()'.
Reference problem? 参考问题? Any help would be appreciated. 任何帮助,将不胜感激。
Edit I tried using a non-nullable date time and that gave the same error. 编辑我尝试使用不可为空的日期时间,并且给出了相同的错误。 Something is trying to call : 某事试图打电话给:
System.Collections.IDictionary NHibernate.ISessionFactory.GetAllClassMetadata()
When I check out ISessionFactory
via vs2010 the medadata does not show the"GetAllClassMetadata()" method. 当我通过vs2010签出ISessionFactory
,medadata不显示“ GetAllClassMetadata()”方法。
Probably linq provider doesn't understand startDate.Value getter call. 可能linq提供程序不理解startDate.Value getter调用。 try 尝试
.Where(x => x.EventDate >= startDate && x.EventDate <= endDate)
UPDATE 更新
BTW, which version of nhibernate are you using? 顺便说一句,您正在使用哪个版本的nhibernate? As far as I remember, .Linq is deprecated, use .Query instead 据我所记得,.Linq已被弃用,请改用.Query
I ended up ripping out my references for fluent/nhibernate. 我最终剔除了流利/休眠的参考资料。 I used nuget to get the fluent package, but there may have been an issue with it. 我使用nuget来获得流利的软件包,但是可能存在问题。 I downloaded the latest assemblies for fluent nhibernate and removed any reference to those asseblies I could find. 我为流利的nhibernate下载了最新的程序集,并删除了我能找到的与这些组件有关的任何内容。 This seems to have fixed the issue. 这似乎已经解决了问题。
BTW...I am now using Query() rather than Linq() 顺便说一句...我现在正在使用Query()而不是Linq()
The NHibernate Linq provider is sometimes a bit buggy. NHibernate Linq提供程序有时会出现问题。 Try to store the method parameters into local variables before using them in the Linq query. 在Linq查询中使用方法参数之前,请尝试将其存储到局部变量中。
public IEnumerable<CalendarItem> GetCalendarItems(DateTime? startDate = new DateTime?(), DateTime? endDate = new DateTime?())
{
if (startDate.HasValue && endDate.HasValue)
{
DateTime? start = startDate.Value;
DateTime? end = endDate.Value;
var items = session.Linq<CalendarItem>()
.Where(x => x.EventDate >= start && x.EventDate <= end)
.ToList<CalendarItem>();
return items;
}
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.