实体框架:检查是否有变化是从一个特定的实体保存 [英] Entity framework: check if there are changes to be saved from a specific Entity
本文介绍了实体框架:检查是否有变化是从一个特定的实体保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想,如果在这里保存之前一组特定的实体所做的更改检测。
I want to detect if changes where made to a specific set of entity before saving.
我目前使用这种方法,但如果有任何实体返回true改性在上下文。
I am currently using this method but it returns true if there are any Entity modified in the context.
const EntityState ModifiedID = EntityState.Modified
| EntityState.Added
| EntityState.Deleted;
var objectStateEntries = Database.LabelTAB
.Context.ObjectStateManager
.GetObjectStateEntries(ModifiedID);
return objectStateEntries.Any();
有没有什么办法,如果有在 LabelTAB一些未保存的条目来检测
实体而已,而不是在整个上下文
?
Is there any way to detect if there are some unsaved entries in the LabelTAB
entity only, and not in the entire Context
?
感谢您。
推荐答案
试试这个:
var objectStateEntries = Database.LabelTAB
.Context
.ObjectStateManager
.GetObjectStateEntries(ModifiedID)
.Where(e => e.Entity is LabelTAB);
return objectStateEntries.Any();
这篇关于实体框架:检查是否有变化是从一个特定的实体保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文