如何判断DataContext有修改:
EF6的
using (var db = new Model1())
{
if (db.ChangeTracker.HasChanges())
{
Console.WriteLine("Something has changed");
}
}
EF5中:
public bool HasUnsavedChanges()
{
return this.ChangeTracker.Entries().Any(e => e.State == EntityState.Added
|| e.State == EntityState.Modified
|| e.State == EntityState.Deleted);
}
EF4中为:
public Boolean HasUnsavedChanges()
{
return (this.ObjectContext().ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified | EntityState.Deleted).Any());
}
DataContext如何放弃修改的建议: