I have a simple Nhibernate Linq query that is returning more results than expected:
var result = (from foo in session.Linq<Foo>()
where foo.High.ID == High.ID
select foo).ToArray();
Foo looks like this:
public class Foo : DomainLayerSuperType
{
// ...other members omitted for clarity
protected IList<Bar> associatedBars;
}
My problem is I get a duplicated Foo for every Bar in the 'associatedBars' collection. So if there are 20 Bars in the collection for an instance of Foo, I get 20 Foo instances, each with 20 Bars.
Mapping for Foo: (FluentNhibernate)
//other mappings omitted
HasMany<Bar>(x => x.AssociatedBars)
.Access.CamelCaseField()
.AsBag()
.Table("dbo.Bar")
.KeyColumn("FooID")
.Cascade.AllDeleteOrphan()
.Inverse()
.Fetch.Join(); //eager load
When I execute this equivalent Hql query, the problem doesn't occur:
var query = new StringBuilder();
query.AppendFormat("select foo from Foo foo where foo.High.ID = {0}", High.ID);
var result = session.CreateQuery(query.ToString()).List<Foo>().ToArray();
Also, when I change the mapping for Foo, to use Lazy loading for AssociatedBars, the problem doesn't occur.
Any ideas? Also, where is best forum for Nh Linq? I couldn't find one so posted here!