检查是否有待保存的待更改 [英] Check if there are any pending changes to be saved

查看:218
本文介绍了检查是否有待保存的待更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

200 200 200 200 200 200 CE X- 2004545 X- 2004545 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 200 X- X-4545454545 X- 20045 X-4545 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 CEEC X- 200 200 200 200 200 200 200 -40 200 200 -40 -40 200 200 -40 200 200 200 200 -40 200 200 200 200 200:20045 200 200 200: b)> 0;

编辑:



改进的代码:

  bool changesMade = context。 
ObjectStateManager。新新新新旗新新新新旗新新旗新新旗新新旗旗新1992新新旗新新旗旗新1992新新新新旗新新旗200新新新新旗新新名:


Is there a way to find out whether there are unsaved changes in my entity context, in the Entity Framework?

解决方案

This might work (if by changes you mean added, removed and modified entities):

bool changesMade = (context.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Count() +
                    context.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted).Count() +
                    context.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Count()
                    ) > 0;

Edit:

Improved code:

bool changesMade = context.
                   ObjectStateManager.
                   GetObjectStateEntries(EntityState.Added | 
                                         EntityState.Deleted | 
                                         EntityState.Modified
                                        ).Any();

这篇关于检查是否有待保存的待更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆