NHibernate: HasMany Components and Where / Contains Position
I am trying to figure out how to create a query using Linq in NHibernate.
I have two classes:
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; }
}
The Foo Bar collection appears as a set of one-to-many components.
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'm not sure if this is correct, but whenever I run this request, I get a NullReferenceException inside the NHibernate.Linq.Visitors.WhereArgumentsVisitor.GetCollectionContainsCriteria method.
Can anyone help me with an alternative way to run this query?
+2
source to share