开发者

Why is a single join query running twice when using nhibernate LINQ syntax?

开发者 https://www.devze.com 2023-02-01 11:06 出处:网络
i just migrated to nhibernate 3 and an using the LINQ syntax.I now have the following code: IEnumerable<Team> team = Session.Query<Team>().Fetch(r=>r.Country);

i just migrated to nhibernate 3 and an using the LINQ syntax. I now have the following code:

IEnumerable<Team> team = Session.Query<Team>().Fetch(r=>r.Country);

so it will do 开发者_StackOverflow社区an upfront join (as i need these child objects for each record.

It is running the join query but I pulled this up in the nhibernate profiler and it turns out that its running the query twice (same exact query).

Is this a bug in the new version of nhibernate or is there something that I am doing wrong?

Also, any suggestions for additional ways to debug this to understand why this is happening.


It has nothing to do with Fetch or joins.

You are assigning an IQueryable to team. Therefore, each time you enumerate it (iterate, get count, etc), it is executing the query.

To avoid this, append .ToList() to the call, so it's executed and converted to an in-memory list.

0

精彩评论

暂无评论...
验证码 换一张
取 消