Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
LINQ Any方法会破坏NHibernate初始化_Linq_Nhibernate - Fatal编程技术网

LINQ Any方法会破坏NHibernate初始化

LINQ Any方法会破坏NHibernate初始化,linq,nhibernate,Linq,Nhibernate,我在使用NHibernate的ASP.NET MVC应用程序中遇到了一个有线问题 在我的域模型中有一个名为IsLeaderBanker(IbEmployee banker)的虚拟方法。推进是这样的: public virtual bool IsLeaderBanker(IbEmployee banker) { return GetLeaderBankers().Any(lb => lb.Id == banker.Id); } public virtual bool IsLeade

我在使用NHibernate的ASP.NET MVC应用程序中遇到了一个有线问题

在我的域模型中有一个名为IsLeaderBanker(IbEmployee banker)的虚拟方法。推进是这样的:

public virtual bool IsLeaderBanker(IbEmployee banker)
{
    return GetLeaderBankers().Any(lb => lb.Id == banker.Id);
}
public virtual bool IsLeaderBanker(IbEmployee banker)
{
    var result = GetLeaderBankers();
    foreach (var b in result)
    {
        if (b.Id == banker.Id)
        {
            return true;
        }
    }
    return false;
}
它简单而流畅。但是,Nhibernate在初始化会话存储时引发异常

The entity '<>c__DisplayClass9' doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id).

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: FluentNHibernate.Visitors.ValidationException: The entity '<>c__DisplayClass9' doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id).

Source Error: 


Line 144:            storage = new WebSessionStorage(this);
Line 145:            NHibernateInitializer.Instance().InitializeNHibernateOnce(
Line 146:                () => NHibernateSession.Init(storage,
Line 147:                                             new[] { Server.MapPath(@"~/bin/IB.Oss.Dal") },
Line 148:                                             AutoPersistenceModelGenerator.Generate(
一切正常。这也是同样的逻辑,Reformer建议我将其更改为LINQ。为什么任何方法都会破坏NHibernate?我多次使用Where和Select,它们都工作得很好

在我的应用程序中,Nhibernate版本是3.3.2。

请尝试以下操作:

public virtual bool IsLeaderBanker(IbEmployee banker)
{
    var id = banker.Id;
    return GetLeaderBankers().Any(lb => lb.Id == id);
}

最好的办法是向NHibernate报告一个bug。