如何查看实体框架生成的SQL?
(在我的特殊情况下,我正在使用mysql提供程序 - 如果它很重要)
我试图通过覆盖SaveChanges()方法使用EF 4.1实现AuditLog,如下所述:
我遇到了"修改"条目的问题.每当我尝试获取相关属性的OriginalValue时,它总是具有与CurrentValue字段中相同的值.
我首先使用此代码,并成功识别修改的条目:
public int SaveChanges(string userID)
{
// Have tried both with and without the following line, and received same results:
// ChangeTracker.DetectChanges();
foreach (
var ent in this.ChangeTracker
.Entries()
.Where(p => p.State == System.Data.EntityState.Added
p.State == System.Data.EntityState.Deleted
p.State == System.Data.EntityState.Modified))
{
// For each change record, get the audit record entries and add them
foreach (AuditLog log in GetAuditRecordsForChange(ent, userID))
{
this.AuditLog.Add(log);
}
}
return base.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
问题在于此(缩写代码):
private List<AuditLog> …Run Code Online (Sandbox Code Playgroud)