我需要断开连接的实体吗? [英] Do I need disconnected entities?

查看:62
本文介绍了我需要断开连接的实体吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序,并且正在使用实体框架。我正在阅读教程

I have a WPF application and am using entity framework. I was reading the tutorial

,而作者谈论的是断开连接的实体,这是我第一次听说它们。对于实际何时需要断开连接的实体,我有些困惑,因为我一直在使用EF对业务对象执行CRUD操作。如果在对业务对象执行CRUD操作时使用的是同一上下文,为什么我需要手动跟踪实体状态更改?谢谢你的帮助。

and the author was talking about disconnected entities, which is the first time I have heard of them. I am a little confused as to when disconnected entities are actually needed, as I have been using EF just fine to do CRUD operations on my business objects. If I am using the same context when I am doing CRUD operations on a business object, why do I need to ever manually track the entity state changes? Thanks for any help.

推荐答案

如果始终围绕原始上下文实例,那么您可能不必担心断开连接的实体。断开连接的实体通常出现在Web服务或网站的上下文中,在该上下文中,最初从中获取实体的上下文(例如,放置在 Session 中)在修改该实体并将其保存回数据库后的某个时间不再可用。

If you are always keeping around the originating context instance, then you probably do not need to worry about disconnected entities. Disconnected entities often come up in the context of web services or web sites, where the context from which an entity was originally retrieved (and, for example, placed into a Session) is no longer available some time down the road when that entity has been modified and needs to be saved back to the database.

这篇关于我需要断开连接的实体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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