D
D
Dmitry Petrov2017-05-24 22:48:35
.NET
Dmitry Petrov, 2017-05-24 22:48:35

Is there an EF6 analogue of EXPLAIN to explain why a query based on Linq2Entities formed the way it did?

When we create a query like
var query = from t1 in dbcontext.table1
join t2 in dbcontext.table2 on ....
we can get the text of the query compiled from the expression tree via query.ToString. This will be the query sent to the DBMS.
But how to understand on the basis of what considerations EF compiled and assembled the query in this form? How to get an explanation that the inner join or left outer join was chosen based on such and such entity attributes, such and such a word in the expression, that where is built for this reason, the columns in select for this reason, and so on?
Yes, I know that the inner workings of EF need to be known and imagine how things work, but when today I spent an hour figuring out why the banal join .... in ... into ... DefaultIfEmpty does NOT give a left outer join (as it turned out - the ForeignKey attribute for the key field was declared in the class, but I somehow forgot about it), I realized that sometimes, to find out the reasons, such an explain would VERY come in handy.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question