Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core 1.0 - Include() generates more than one queries

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:

Query 1

And

Query 2

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

Thanks

like image 929
regnauld Avatar asked Feb 21 '16 13:02

regnauld


1 Answers

Yes, it’s normal even in one to many scenarios.

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

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

like image 199
Jonathan Magnan Avatar answered Oct 31 '22 06:10

Jonathan Magnan