AFract
AFract

Reputation: 9680

Getting SQL queries generated with Entity Framework Plus?

I am enjoying the features of Entity Framework Plus over Entity Framework 6 since a few hours, and especially its IncludeFilter.

With regular Entity Framework 6, I was able to simply call ToString() on an IQueryable to easily get the SELECT query that will be actually processed on DB Server.

But with EF+, when I apply an IncludeFilter, I only get :

 Z.EntityFramework.Plus.QueryIncludeFilterParentQueryable`1[MyRecord]

Because ToString() seems to not be overloaded the same way in EF+.

Is there a way to get SQL generated for "IncludeFilter" queries as well as for classical queries ?

I know I could get it on SQL server itself with the adequate profiling tools, but I would like to be able to do it on code side in EF.

Upvotes: 1

Views: 1147

Answers (3)

AbuDawood Oussama
AbuDawood Oussama

Reputation: 923

You can use the current context's log to track all requests performed under this instance

        context.Database.Log = s => Console.WriteLine(s);

Upvotes: 1

lokalmatador
lokalmatador

Reputation: 31

Maybe a little late but you could use SQL Server Profiler to trace database events (e.g., queries). Using SQL Tuning profile it will trace your queries and you can have a look at them in SQL.

Upvotes: 2

Jonathan Magnan
Jonathan Magnan

Reputation: 11337

Is there a way to get SQL generated for "IncludeFilter" queries as well as for classical queries ?

No, there is currently no way.

It might come later but at this moment, the library doesn't offer this feature.

(I'm the owner)

EDIT: Answer comment

My main worry was to know if the generated queries are optimized

I would not call them optimized. They are generated by Entity Framework and nothing is really modified on our side.

  • IncludeFilter: Create one VERY big query like Include does in EF6
  • IncludeOptimized: Create multiple small queries like Include does in EF Core

Upvotes: 2

Related Questions