2

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?

3
  • 2
    "custom SQLs (created using DbCommand)" - why? Just use context.Query<T>.FromSql("Query")? Commented Aug 12, 2019 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. Commented Aug 12, 2019 at 12:38
  • Can you update the post with your configurations and a custom sql call? To understand better your problem Commented Sep 16, 2019 at 13:45

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.