views:

220

answers:

2

Hi, I'm trying to work out how to create a query using Linq to NHibernate.

I have two classes like this:

public class Foo
{
    private ISet<Bar> _bars = new HashedSet<Bar>();
    public virtual ISet<Bar> Bars
    {
        get { return _bars; }
        set { _bars = value; }
    }
}

public class Bar
{
    public string Name { get; set; }
    public string Color { get; set; }
}

Foo's Bar collection is mapped as a one-to-many component collection.

Now I want to run a query that should look something like this:

var myBar = new Bar { Name = "test", Color = "testColor" };

var matchingFoos = Session.Linq<Foo>
                   .Where(foo => foo.Bars.Contains(myBar),
                          new BarEqualityComparer())
                   .ToList();

I am not sure if this is correct, but whenever I run this query I get a NullReferenceException from inside a method called NHibernate.Linq.Visitors.WhereArgumentsVisitor.GetCollectionContainsCriteria method.

Could anyone help me out with an alternative means of running this query?

A: 

I'm having the same issue - did you manage to resolve this at all?

Cheers

Rob

+1  A: 

The BarEqualityComparer will be the point of failure for sure. There is no simple way for the provider to translate custom class to an SQL statement.

Rashack