查找变更集的实体框架 [英] Finding the Changeset in Entity Framework
本文介绍了查找变更集的实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用EF4库在ASP.NET MVC3 / WCF应用程序。我使用的工作模式的单位将更改应用到数据库
其中一个用户的需求是有变化的实体列表中创建一票/电子邮件。有没有一种方法,我可以在下面的功能的实体检测只对变化的特性?
公共无效UpdateTrackedEntity< T>(T modifiedEntity)其中T:类
{
VAR组= CreateObjectSet< T>();
set.ApplyCurrentValues(modifiedEntity);
}
解决方案
是有一种方法:
公共无效UpdateTrackedEntity< T>(T modifiedEntity)其中T:类
{
VAR组= CreateObjectSet< T>();
set.ApplyCurrentValues(modifiedEntity);
VAR项= ObjectStateManager.GetObjectStateEntry(modifiedEntity);
//条目有两个集合:CurrentValues(您应用)和
// OriginalValues(来自数据库加载)
//它也有方法GetModifiedProperties得到收集修改
//属性名称。
}
检查 ObjectStateEntry 了解更多详情。
I am using EF4 repositories in a ASP.NET MVC3/WCF application. I am using the Unit of Work pattern to apply changes to the database
One of the user requirements is to create a ticket/email with a list of changes to the entity. Is there a way I can detect only the changed properties on an entity in the following function?
public void UpdateTrackedEntity<T>(T modifiedEntity) where T : class
{
var set = CreateObjectSet<T>();
set.ApplyCurrentValues(modifiedEntity);
}
解决方案
Yes there is a way:
public void UpdateTrackedEntity<T>(T modifiedEntity) where T : class
{
var set = CreateObjectSet<T>();
set.ApplyCurrentValues(modifiedEntity);
var entry = ObjectStateManager.GetObjectStateEntry(modifiedEntity);
// entry has two collections: CurrentValues (those you applied) and
// OriginalValues (those loaded from DB)
// It also have method GetModifiedProperties to get collection of modified
// property names.
}
Check ObjectStateEntry for more details.
这篇关于查找变更集的实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文