【问题标题】:NHibernate LINQ throws "The binary operator Equal is not defined for the types 'System.Collections.Generic.IList`1[System.Int32]' and 'System.Int32'"NHibernate LINQ 抛出“二元运算符 Equal 没有为类型 'System.Collections.Generic.IList`1[System.Int32]' 和 'System.Int32' 定义”
【发布时间】:2010-10-18 06:56:53
【问题描述】:

以下 LINQ to NHibernate(使用 NHibernate 3.0)导致 System.InvalidOperationException 被抛出,并显示消息“二进制运算符 Equal 没有为类型 'System.Collections.Generic.IList`1[System.Int32] 定义' 和 'System.Int32'"

public IEnumerable<ProjectSummary> GetProjects( IList<int> clients )
{
    using ( var session = _sessionManager.OpenSession() )
    {
        var q = from p in session.Query<Project>()
                where clients.Contains( p.Client.Id )
                select new ProjectSummary()
                {
                    ProjectId = p.Id,
                    Active = p.Active,
                    ClientId = p.Client.Id,
                    Name = p.Name

                };

        return q.ToList();
    }
}

【问题讨论】:

    标签: c# linq nhibernate linq-to-nhibernate


    【解决方案1】:

    此问题已在后备箱中修复。

    对于任何其他涉及 Equals 的 System.NotSupportedExcpetion,您可以查看我博客上的这篇文章: http://www.primordialcode.com/Blog/Post/nhibernate-3-extending-linq-provider-fix-notsupportedexception

    【讨论】:

    • 好文章。不知道你可以这样扩展它。
    【解决方案2】:

    使用List&lt;int&gt; 而不是IList&lt;int&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-11
      相关资源
      最近更新 更多