WPF - EF5 - 检测objectContext的单个实例上的更改 [英] WPF - EF5 - Detect changes on a single instance of an objectContext

查看:95
本文介绍了WPF - EF5 - 检测objectContext的单个实例上的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧



我正在使用实体框架5,



是否有可能,或者有没有办法只检测对象的单个实例中的更改而不是所有对象上下文?



我想要做的是:



人员=新人();



人。 //在这里做一些改变



person.DetectChanges();



而不是:



人员=新人();



人。 //在这里做一些改变



allObjectContext.DetectChanges();







我是否有意义?



Plz让我知道!



谢谢!

Hello there guys

I'm using entity framework 5,

is it possible, or is there a way of only detect changes in a single instance of an object rather than the all object context?

what i want to do is like:

Person person = new Person();

person. // make some changes here

person.DetectChanges();

rather than:

Person person = new Person();

person. // make some changes here

allObjectContext.DetectChanges();



I'm i making sense?

Plz let me know!

Thanks!

推荐答案

第一个问题是为什么?由于你正在创建一个新的Person对象,几乎所有东西都将是一个变化。唯一不会是对象属性类型的默认值,例如0表示 int
The first question is Why?? Since you're making a new Person object, nearly everything will be a change. The only things that won't will be the default values for your object property types, like 0 for an int.


你好感谢回复。



我想要做的是当我在一个实例上设置一个属性时,如果我使用DetectChanges()它会自动填充导航属性反之亦然。



发生的事情是检测更改检测到对象上下文中加载的所有对象,在我的例子中是数据库是远程的,所以需要一段时间。



可以说,检测3000条记录的变化需要2-3秒。



我想在单个记录中执行此操作(加载导航属性)以缩短时间。



谢谢!
Hello there and thanks for the reply.

What i want to do is when i set a property on an instance, if I use "DetectChanges()" it automatically populates the navigational property and vice-versa.

What is happening is that the detect changes detect that to ALL the objects loaded in the object context, and, in my case, the database is remote, so it takes a while.

Lets say, it take like 2-3 seconds detecting the changes of 3000 records.

I want to do that (load navigational properties) in a single record to improve time.

Thanks!


这篇关于WPF - EF5 - 检测objectContext的单个实例上的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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