[英]Getting Exception when using NHibernate 2.1 Linq<T> , why?
When using the NHibernate 2.1 with Linq assembly, we get an exception when trying to enumerate the results or invoking ToList(). 将NHibernate 2.1与Linq程序集一起使用时,尝试枚举结果或调用ToList()时会出现异常。
we have a list of Id
that we want to get the records of them, we used the following code 我们有一个
Id
列表,我们想要获取它们的记录,我们使用了以下代码
public List<TEntity> GetAllContainsItems<TEntity>(List<int> ids)
where TEntity : IEntity
{
using (IUnitOfWork uof = _container.Resolve<IUnitOfWork>())
{
uof.Initialize();
IRepository<TEntity> rep
= _container.Resolve<IRepository<TEntity>>();
// repository exposes the ISession.Linq<T> of nhibernate.
var res = rep.Find().Where(y => ids.Contains(y.Id) );
// get the exception:
// "Object reference not set to an instance of an object."
return res.ToList();
}
}
any thoughts ? 有什么想法吗 ?
PS We can't change the Dll for now . 附注:我们目前无法更改DLL。
Can you change your code to the following and see if it works: 您可以将代码更改为以下代码,看看是否可行:
if(ids==null)
{
Console.WriteLine("Why am I not surprised");
}
var res = rep.Find().Where(y => y!=null && ids.Contains(y.Id));
return res.ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.