Tom
Tom

Reputation: 139

Log all linq queries executed on DbContext - C#

Is there a simple way to log all linq queries executed in an application?

I am currently using code first entity framework with a DbContext instead of the older DataBaseContext.I know for a fact that the DataBaseContext class has a Log property, but i do not know if there is something like the log property for the DbContext.

Upvotes: 4

Views: 1950

Answers (1)

Anatolii Gabuza
Anatolii Gabuza

Reputation: 6260

You can use .ToString() on IQueryable queries that you'll create. It will return SQL statement that will be executed on DB.
Then if you're using Repository pattern you can implement your logging logic without using any third-party libs.

Upvotes: 1

Related Questions