© Holger Schwichtenberg 2018
Holger SchwichtenbergModern Data Access with Entity Framework Core https://doi.org/10.1007/978-1-4842-3552-2_12

12. Logging

Holger Schwichtenberg1 
(1)
Essen, Germany
 
In the classic Entity Framework, there are two easy ways to get the SQL commands that the OR mapper sends to the database.
  • You can call ToString() on a query object (IQueryable<T>).

  • You can use the Log attribute (since Entity Framework version 6.0), as in ctx.Database.Log = Console.WriteLine;.

Unfortunately, neither of these options is available in Entity Framework Core.

The following command

var query = ctx.FlightSet.Where(x => x.FlightNo > 300).OrderBy(x => x.- Date).Skip(10).Take(5);
Console.WriteLine (query.ToString());

only delivers the following output: ...

Get Modern Data Access with Entity Framework Core: Database Programming Techniques for .NET, .NET Core, UWP, and Xamarin with C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.