简体   繁体   English

实体框架5日志数据库在运行时更改

[英]Entity Framework 5 log database changes at runtime

In an ASP.NET 4.5 C# Entity Framework 5 Code First project I'd like to log the changes being made in the database at runtime (the logging has to be done in the asp.net app, not at the database). 在ASP.NET 4.5 C#Entity Framework 5 Code First项目中,我想记录在运行时在数据库中进行的更改(日志记录必须在asp.net应用程序中完成,而不是在数据库中完成)。 Previously, the SQL statements were built by the code, and those statements were simply logged. 以前,SQL语句是由代码构建的,而这些语句只是被记录下来。 Now with EF, the object is retrieved via linq to entities, modified and 现在使用EF,通过linq将对象检索到实体,修改和

db.SaveChanges();

is being called. 被称为。 My first idea was to retrieve the actual SQL statements that EF sends to the DB -- this seems to be rather complex, however. 我的第一个想法是检索EF发送给数据库的实际SQL语句 - 但这似乎相当复杂。 I've found many "solutions" for displaying the SQL during debugging, but no simple way for the code to retrieve it at runtime. 我发现了许多用于在调试期间显示SQL的“解决方案”,但代码在运行时没有简单的方法来检索它。

So I'm looking for any solution that can log the changes being made (either the SQL being sent to the DB [preferred], or some other form of textual representation of the changes made to the object), and that doesn't require the inclusion of a number of complex debug libraries. 所以我正在寻找能够记录所做更改的任何解决方案(要么将SQL发送到DB [首选],要么对对象所做的更改的其他形式的文本表示),这不需要包含许多复杂的调试库。

You should try FrameLog 你应该试试FrameLog

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

It is not clearly stated but it supports Entity Framework 5 它没有明确说明,但它支持实体框架5

I haven't tested this on EF 4.5 so it may need to be tweaked a bit, but I find for debugging purposes the extension method written at the bottom of this post: 我没有在EF 4.5上测试过这个,所以可能需要稍微调整一下,但我发现在本文的底部写的扩展方法用于调试:

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

Gives me the correct output of my entities.SaveChanges() call. 给我的entities.SaveChanges()调用的正确输出。 It doesn't require any external libraries and since it's written as an extension method it won't clog up your code. 它不需要任何外部库,因为它是作为扩展方法编写的,所以它不会阻塞你的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM