views:

634

answers:

1

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

+2  A: 

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.

bbmud
It is a bug, this also helps explain it: http://ayende.com/Blog/archive/2006/05/02/CombatingTheSelectN1ProblemInNHibernate.aspx
Andrew Bullock