相关疑难解决方法(0)

如何查看实体框架生成的SQL?

如何查看实体框架生成的SQL?

(在我的特殊情况下,我正在使用mysql提供程序 - 如果它很重要)

ado.net entity-framework

587
推荐指数
18
解决办法
29万
查看次数

实体框架DbContext SaveChanges()OriginalValue不正确

我试图通过覆盖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)

c# entity-framework ef-code-first entity-framework-4.1

7
推荐指数
2
解决办法
2万
查看次数