Linq to SQL:如何确定更改了哪些对象属性? [英] Linq to SQL: How to determine which object properties are changed?

查看:105
本文介绍了Linq to SQL:如何确定更改了哪些对象属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在dataContext.submitChanges()更新对象之前,我需要为Linq to SQL对象编写一些CRUD数据验证方法。 

我认为Linq可能会为那些已更改的属性维护一个用户可访问的对象属性集合。 

或者我是否必须使用蛮力昂贵的路线并遍历所有属性以找到已更改的属性?

谢谢,  -BGood

解决方案

看看 DataContext.GetChangeSet方法。您可以使用它来访问以下 ChangeSet属性:插入,更新和删除。

请记住,这些是在实际提交之前进行的跟踪更改,因此无法准确反映可能发生的情况(即,一旦提交操作可能会失败)。

I need to program some CRUD data validation methods for Linq to SQL objects before the object is updated by dataContext.submitChanges(). 

I thought Linq might maintain a user-accessible collection of object properties for those properties which have changed. 

Or do I have to go the brute force expensive route and iterate over all of the properties to find those that have been changed?

Thanks,  -BGood

解决方案

Take a look at the DataContext.GetChangeSet method . You can use it to access the following ChangeSet properties : Inserts, Updates, and Deletes.

Bear in mind that these are tracked changes before an actual submission occurs, and therefore don't accurately reflect what may occur (ie. an action could fail once submitted).


这篇关于Linq to SQL:如何确定更改了哪些对象属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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