EF Core 1.0-Include()生成多个查询 [英] EF Core 1.0 - Include() generates more than one queries

查看:249
本文介绍了EF Core 1.0-Include()生成多个查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EF 7.0.0-rc1-final。

I am using EF 7.0.0-rc1-final.

以下语句在服务器上生成多个查询。
这是正常现象还是我缺少什么?

The following statement generates multiple queries on the server. Is this normal or I am missing something ?

Group myGroup = dbContext_
            .Set<Group>()
            .Include(x => x.GroupRoles)
            .ThenInclude(x => x.Role)
            .FirstOrDefault(x => x.Name == "Approver");

我在服务器上看到两个独立的查询:

I see two separate queries executed on the server:

这是标准的多对多方案。为什么是第一个查询?

It's a standard many-to-many scenario. Why is the first query ?

谢谢

推荐答案

是的

EF7生成多个查询以避免多次返回相同的数据。

EF7 generates multiple queries to avoid returning the same data multiple times.

以下是有关EF6 Include的精彩文章,以了解为什么EF7需要进行此更改:实体框架的陷阱,包括

Here is a great post about EF6 Include to understand why this change was required for EF7: Entity Framework pitfalls, include

这篇关于EF Core 1.0-Include()生成多个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆