Is there a way to find out whether there are unsaved changes in my entity context, in the Entity Framework?
相关问题
- Entity Framework Code First Migration
- Entity Framework throws exception - Network Relate
- How to Specify a Compound key in Entity Framework
- Slow loading first page - ASP.NET MVC
- query and create objects with a one to many relati
相关文章
-
EF6 DbSet
returns null in Moq - Entity Framework 4.3.1 failing to create (/open) a
- EF6 code first: How to load DbCompiledModel from E
- Why do I need a ToList() to avoid disposed context
- Code-First Add-Migration keeps adding the same col
- EF Codefirst validate unique property?
- EF Core 'another instance is already being tra
- Add XML documentation / comments to properties/fie
Starting with EF 6, there is
context.ChangeTracker.HasChanges()
.This might work (if by changes you mean added, removed and modified entities):
Edit:
Improved code:
For those of you using EF 4+, here is an equivalent solution as an extension method:
Note that you can't combine the values as a bit mask. The function
GetObjectStateEntries()
handled the logic for you, but LINQ won't produce proper results.