EF 4 CTP5,变更跟踪和Ria服务 [英] EF 4 CTP5, change tracking, and Ria Services

查看:62
本文介绍了EF 4 CTP5,变更跟踪和Ria服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CTP 5和RIA服务。 我正在使用遗留数据库,因此我在数据库优先使用POCO(我使用数据构建了一个edmx模型,并使用DbContext T4模板生成了POCO。)


我有无法理解变更跟踪。 在服务器端,我需要检测对实体的各个列/属性的更改。 这是因为我必须进行审核(例如"Sue在2011年5月2日1:30更改了名字字段")。


看起来有多层变化跟踪(DomainService中的ChangeSet和DbContext中的ChangeTracking),但似乎没有人真正得到我想要的东西(我需要原始值,甚至是数据库值)。


<我可以手动重新查询数据库,但看起来好像已经完成了一些工作来启用EF内部的更改跟踪(自动检测更改/更改跟踪器等)。 我想和EF的其余部分玩得很好。 检测
更改的最佳方法是什么?


 

解决方案

<我不确定你是否看过下面的文章。它给出了如何使用原始/当前/数据库值的很好的解释。


http://blogs.msdn.com/b/adonet/archive/2011/01 /30/using-dbcontext-in-ef-feature-ctp5-part-5-working-with-property-values.aspx


 


I am using CTP 5 with RIA Services.  I am working with a legacy DB, so I am using POCO's with Database First (I built an edmx model from the data and generated POCO's with the DbContext T4 template.)

I'm having trouble understanding change tracking.  On the server side, I need to detect changes to the individual columns/properties of the entity.  This is because I have to do auditing (like "Sue changed the First Name field at 5:30 2/1/2011").

It looks like there are multiple layers of change tracking (a ChangeSet in the DomainService, and a ChangeTracking in the DbContext), but neither one really seems to get me what I want (I need the original values, or even the database values).

I could manually requery the database, but it looks as though some work was done to enable change tracking inside of EF (Autodetect changes/the change tracker, etc).  I want to play nice with the rest of EF.  What is the best way to go about detecting changes?

 

解决方案

I am not sure if you have seen the below article. It gives a good explanation on how to use original / current / database values.

http://blogs.msdn.com/b/adonet/archive/2011/01/30/using-dbcontext-in-ef-feature-ctp5-part-5-working-with-property-values.aspx

 


这篇关于EF 4 CTP5,变更跟踪和Ria服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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