Andrew Bullock
Andrew Bullock

Reputation: 37398

FirstOrDefault() breaks FetchType=join with Linq to NHibernate

If i do

Session.Linq<MyClass>().Where(x => x.Id = someId).FirstOrDefault();

where MyClass has a set of eager loaded child object on it, the FirstOrDefault() seems to prevent this from working by adding a TOP 1 to the SQL.

Is this just a bug (feature?) in Linq2NH (which i understand is being rewritten) or am I missing something?

Is there a preferred alternative which works properly?

Thanks

Upvotes: 2

Views: 1487

Answers (1)

bbmud
bbmud

Reputation: 2688

Looks like a bug, in my opinion FirstOrDefault is a pretty well defined Linq operator and it has nothing to do with eager/lazy loading, so it should not break it.

I guess there are lots of such nuances, which cause that the library is not production ready. I suggest submitting the bug the the devs.

Falling back to DetachedCriteria (or HQL) in this case is the only option in my opinion.

Upvotes: 3

Related Questions