Entity Framework 5 Database Runtime Changes

In an ASP.NET 4.5 C # Entity Framework 5 Code First project, I would like to log changes made to the database at runtime (logging should be done in the asp.net application, not the database). Previously, SQL commands were created code, and these statements were simply logged. Now with EF, the object is retrieved via linq for objects modified and

db.SaveChanges(); 

. My first idea was to get the actual SQL statements that EF sends to the database - this seems rather complicated. I found many “solutions” for displaying SQL during debugging, but an easy way for code to not get it at runtime.

So, I'm looking for any solution that can log changes made (either SQL sent to the database [preferred], or some other form of textual representation of the changes made to the object), and that doesn't require the inclusion of several complex debug libraries.

+4
source share
2 answers

You should try framelog

https://bitbucket.org/MartinEden/framelog/wiki/Home

This is not explicitly stated, but supports Entity Framework 5

+1
source

I have not tested this on EF 4.5, so it may need to be slightly adjusted, but I find for debugging purposes the extension method written at the bottom of this post:

http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/2a50ffd2-ed73-411d-82bc-c9c564623cb4/

Gives me the correct conclusion of my entities. call SaveChanges (). It does not require any external libraries, and since it is written as an extension method, it will not clog your code.

0
source

Source: https://habr.com/ru/post/1447447/


All Articles