views:

28

answers:

2

The following LINQ to NHibernate (using NHibernate 3.0) results in a System.InvalidOperationException being thrown 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();
    }
}
A: 

Use List<int> instead of IList<int>

David Gardiner
+2  A: 

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

Alessandro Gianbattista Giorge
Good article. Didn't know you could extend it like that.
David Gardiner