I have 2 objects like this
public class Child
{
public virtual int ChildId { get; set; }
}
public class Parent
{
public virtual int ParentId { get; set; }
public virtual IList<Child> Children { get; set; }
}
I am trying to write a linq to nhibernate query to select a parent where it contains a child with a specific id. return x => x.Children.Contains
does not work. I also tried this.
return x => (from y in x.Children where y.ChildId.Equals(childId) select y).Count() > 0
My fluent mapping looks like this
HasManyToMany<Child>(x => x.Children)
.Table("ParentsChildren")
.ParentKeyColumn("ParentId")
.ChildKeyColumn("ChildId");
How can I find the parent that contains a child by id?
ParentsChildren
table and use that object in my query. Then I use linq to select the parent(s) from the composite objects returned by my query. – Sinew