Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top