实体框架ObjectContext:并发 [英] Entity Framework ObjectContext: Concurrency

查看:124
本文介绍了实体框架ObjectContext:并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用具有Entity Framework和Repository模式的MVC应用程序
在此应用程序中,最终用户可以在会话期间通过多个http请求修改不同的实体数据。 (向导页面的类型)
然而,他们提交这些修改,直到最后一个提交按钮被点击
这些也有选择离开这种情况下,他们的工作应该回滚。



我想知道如果两个用途都做同样的事情,其中​​一个点击提交按钮
,我猜这两个用户的更改提交!!!会发生什么!



我想我需要通过用户连接或会话创建一个对象上下文
非常欢迎您的意见

解决方案

上下文应该只使用一次来获取最初的数据,一次用于持久化。

(没有长期的多http请求上下文)。



这样做:


  1. 创建上下文,

  2. 以任何您喜欢的方式(不使用上下文)管理用户对多个请求的数据更改,例如会话,隐藏字段等。

  3. 创建上下文,保留修改的实体,处理上下文。

关于步骤2 - 我建议使用特定对象( ViewModels ),而不是 EntityObjects >视图用于用户交互。


I am trying to use an MVC application with Entity Framework and Repository pattern In this application, an end user may modify different entities data through multiple http requests during their session. (kind of wizard pages) However they do commit these modifications until a final commit button is clicked These also have the option to leave and this case, their work should be rollbacked.

I am wondering what would happen if two uses are doing the same and one of them clicks the commit button I guess changes made by both users are committed !!!

I guess I need to create a object context by user connection or by session Your comments are very much welcome

解决方案

The context should be used only once for fetching the data initially and once for persisting.
(No long-lived 'multi-http-request' contexts).

So what you do is this:

  1. Create context, fetch data, dispose of context.
  2. Manage user changes to the data across multiple requests in whatever way you like (without using the context), e.g. Session, hidden fields, etc.
  3. Create context, persist modified entities, dispose of context.

Regarding step 2 - I recommend using specific objects (ViewModels) rather than EntityObjects in the Views for user interaction.

这篇关于实体框架ObjectContext:并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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