开发者

NHibernate LINQ throws "The binary operator Equal is not defined for the types 'System.Collections.Generic.IList`1[System.Int32]' and 'System.Int32'"

开发者 https://www.devze.com 2023-01-20 18:10 出处:网络
The following LINQ to NHibernate (using NHibernate 3.0) results in a System.InvalidOperationException being th开发者_如何学运维rown with the message \"The binary operator Equal is not defined for the

The following LINQ to NHibernate (using NHibernate 3.0) results in a System.InvalidOperationException being th开发者_如何学运维rown with the message "The binary operator Equal is not defined for the types 'System.Collections.Generic.IList`1[System.Int32]' and '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();
    }
}


This problem has been fixed in the trunk.

For any other System.NotSupportedExcpetion involving Equals you can look at this post on my blog: http://www.primordialcode.com/Blog/Post/nhibernate-3-extending-linq-provider-fix-notsupportedexception


Use List<int> instead of IList<int>

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号