简体   繁体   English

使用NHibernate 2.1 Linq时获取异常 <T> ,为什么呢?

[英]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.

相关问题 在 .Net Core 2.1 中使用 FirstOrDefault 时抛出 System.Linq.Expressions 异常 - System.Linq.Expressions exception thrown when using FirstOrDefault in .Net Core 2.1 为什么在使用nhibernate LINQ语法时单个联接查询运行两次? - Why is a single join query running twice when using nhibernate LINQ syntax? 在升级到nhibernate 3.0后使用linq时为什么不运行任何查询 - Why dont any queries get run when using linq after upgrading to nhibernate 3.0 使用System时,我仍然收到null异常。管理无法弄清原因 - I'm still getting null exception when using the System.Management can't figure out why Linq查询nhibernate; 不支持的例外 - Linq query nhibernate; not supported exception 使用Fluent NHibernate时映射异常 - Mapping exception when using Fluent NHibernate 使用LINQ和NHibernate - Using LINQ with NHibernate 在Linq和Nhibernate中使用Count()时,不支持指定的方法 - Specified method is not supported when using Count() in Linq with Nhibernate 给定一个DateTime,使用LINQ NHibernate时如何调用.ToUniversalTime? - Given a DateTime, how to Call .ToUniversalTime when using LINQ to NHibernate? 在控制台应用程序中使用CommonOpenFileDialog时,为什么会出现此异常? - Why am I getting this exception when using CommonOpenFileDialog in a Console Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM