0

I use EF Core and ADO.NET for custom SQLs. I get all EF Core SQLs in my log files, but I do not see my custom SQLs (created using DbCommand).

How to log ALL SQLs my .net core app sends to the database?

wxt
  • 495
  • 1
  • 5
  • 12
  • 2
    _"custom SQLs (created using DbCommand)"_ - why? Just use `context.Query.FromSql("Query")`? – CodeCaster Aug 12 '19 at 10:12
  • 1
    Well one good reason to use ADO.NET in conjunction with EF is of course to optimize SQL queries beyond what EF is capable of. EF does have a significant overhead cost, even when only executing `.FromSql("Query")`. However that overhead does include logging capability. ADO.NET does not have logging, you'll have to write that yourself. – Adam Vincent Aug 12 '19 at 12:38
  • Can you update the post with your configurations and a custom sql call? To understand better your problem – Pedro Brito Sep 16 '19 at 13:45

1 Answers1

0

ADO.NET does not have logging (thank you @adam-vincent).

When performance is not an issue, Query types may be created as described in Raw SQL Query without DbSet and Entity framework Core Raw SQLQueries with custom model for context.Query<T>.FromSql("Query").

Trying to query a type that is not registered as a 'query type' results in an error "System.InvalidOperationException: Cannot create a DbSet for 'ReportStatusCount' because this type is not included in the model for the context.".

Query types must have properties not fields.

wxt
  • 495
  • 1
  • 5
  • 12