jenson-button-event
jenson-button-event

Reputation: 18941

NHIbernate fetch returning multiple parent objects

Can anyone explain why this query would return 12 companies (it has 12 UserAccessList children)

var list = session.QueryOver<Company>()
        .Where(x => x.Id == 1) //x => x.Id.IsIn(ids))
        .Fetch(l => l.UserAccessList).Eager()
        .List<Company>();

Upvotes: 1

Views: 580

Answers (2)

Sly
Sly

Reputation: 15217

Because in SQL its going to be something like:

select * from 
Companies c left outer join UserAccessLists uac on c.Id == uac.CompanyId
where c.id = id

And it is giving duplicates in results. How to fix such issues you can read here.

Upvotes: 2

jenson-button-event
jenson-button-event

Reputation: 18941

This also works

var c = session.QueryOver<Company>()
        .Future();

 session.QueryOver<Company>()
        .Fetch(l => l.UserAccessList).Eager()
        .Future();

var list = c.ToList();

Upvotes: 1

Related Questions