问题描述
在我的在线考试项目中, WCF 有4种方法:
1)GetSections ------ --------------仅选择部分
2)GetExamDetails --------------- - 从数据库中选择考试详情
3)GetQuestionsAndInsert ----------选择问题并在考试表中插入
4)UpdateAttempt ------------------更新db中的尝试
这些方法在用户点击考试链接时执行。当2个或更多用户点击该链接时,检查页面会成功加载,但如果 2个用户同时点击同一个链接,那么任何一个方法中的任何一个或两个都会从上面获得错误。交易失败等错误,在其他交易正在运行时无法读取数据等。
我在项目中使用了实体框架。我知道它是并发问题但我无法解决它。请告诉我如何解决这个问题。
请尽快回复。
谢谢。
In my online exam project there are 4 methods in WCF:
1)GetSections--------------------Select only sections
2)GetExamDetails-----------------Select exam details from db
3)GetQuestionsAndInsert----------Select questions and insert in Exam table
4)UpdateAttempt------------------Update attempts in db
These methods are executed when user click on exam link. When 2 or more users click on that link exam page get load successfully but if 2 users click on same link at same time then any one of then or both get error from above any 1 method. Errors like transaction failed,can not 'read' data while other transaction is running etc.
I used Entity Framework in my project. I know it is concurrency issue but I am not able to resolve it. Please tell me how to manage this problem.
Please reply ASAP.
Thank you.
推荐答案
My problem resolved. I have declared entity object globally so that I got this error. Now I declare separate object in each method and my problem is solved.
Explanation : As entity object is globally declared all methods run on same object. They are not able to do operations on database by same object and transaction get failed.
这篇关于如何在Entity框架中维护并发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!