0

Im new with VB.NET language and i need to log all queries generated in diferent controllers (SELECTs, UPDATEs, INSERTs and DELETEs). I have tried to search about this topic but all i found it is about EF6+ or C# which i have problems to migrate to VB.NET.

Im using a DbContext with references to all models defined in database and want to log any query generated by LINQ. Can someone help me?

Topics i have looked How do I view the SQL generated by the Entity Framework? How can I debug the SQL generated by EF5 during runtime? Entity Framework 4.1 - EFTracingProvider Log Queries executed by Entity Framework DbContext

I imagine that i need to define a logger attached to database in the DbContext (i saw it in EF6+ it is easy) but when i search about this in EF5, i dont find util documentation.

PD: The project use EF 5.0.0 and .NETFramework v4.5

JaiAG
  • 1
  • 3
  • Most of the topics you quoted in your question have the right answer for EF 5 as well. Unfortunately, the only way you can do this in EF5 is by converting to ObjectQuery (see the accepted answer in your first topic - it just needs to be done in VB). You can also monitor the queries on the database server, if you want an approach which doesn't depend on the programming language: https://www.vanacosmin.ro/articles/EntityFrameworkInterceptQueries#SQLServerProfiler – Cosmin Vană Apr 22 '20 at 14:10
  • @CosminVană I tried some topics (link in OP) and it works but it implies to do it for each controller in the app, I was looking for a answer to apply it to all queries to prevent this because i had hope because you can do it easy in EF6. If i migrate project to EF6, does it imply problem or something between this two versions? – JaiAG Apr 22 '20 at 14:15
  • Unfortunately, you won't find anything easy like in EF6 (like using interceptors). However, the thing which will work is EFTracingProvider (also in your OP). It will require some work to implement it in VB (as most sources are in C#), but this is a direction which will lead to the desired result. Should work by enabling Tracing and plugging in a trace listener. Here is similar question as the one in your OP: https://stackoverflow.com/questions/15829898/logging-sql-statements-of-entity-framework-5-for-database-first-aproach – Cosmin Vană Apr 22 '20 at 14:23

0 Answers0