optimistic-concurrency

How to enable concurrency checking using EF 5.0 Code First?

给你一囗甜甜゛ 提交于 2019-12-10 02:48:58
问题 I would like to do a check-then-update in an atomic operation. I am using dbcontext to manage the transaction. I was expecting to get an exception if the record has been modified by another thread but no exception is thrown. Any help would be appreciated. Here's my output: Thread-4: Reading... Thread-5: Reading... Thread-5: Updating destination 1 Thread-4: Updating destination 1 Thread-4: SaveChanges Thread-5: SaveChanges Here's my code snippet: public static void Main(string[] args) {

MongoDB Optimistic Concurrency Control With .NET

爱⌒轻易说出口 提交于 2019-12-09 17:43:00
问题 Using the .NET MongoDB API (MongoDB.Driver), what is the recommended approach for implementing optimistic concurrency control? For example, is there anything analogous to SQL Server's ROWVERSION/TIMESTAMP, e.g., a property that is automatically updated whenever the document changes? Or is there a trigger mechanism? Or any other mechanism? 回答1: There isn't anything built-in regarding optimistic concurrency in MongoDB. You need to implement that yourself if you need it. You can do that by

Solving Optimistic Concurrency Update problem with Entity Framework

我与影子孤独终老i 提交于 2019-12-06 12:54:31
问题 How should I solve simulation update, when one user updates already updated entery by another user? First user request 'Category' entityobject, second user does the same. Second user updates this object and first user updates. I have field timestamp field in database that wa set to Concurrency Mode - Fixed. This is how I update: public class CategoriesRepository : BaseCategoryRepository { public void Update(....) { try { Category catToUpdate = (from c in Contentctx.Categories where c

Getting latest rowversion/timestamp value in update statement - Sql Server

放肆的年华 提交于 2019-12-06 01:44:49
问题 I'm using rowversion columns for handling optimistic concurrency and want to get the new rowversion value back when I've done an update so that my data layer has the latest value and can perform another update with getting a concurrency exception (unless the record has been update by someone else). I was just doing a get in the data layer after doing an update but this wasn't very efficient or perfectly reliable. For the following table: CREATE TABLE PurchaseType ( PurchaseTypeCode nvarchar

RESTful API and bulk operations

半腔热情 提交于 2019-12-06 01:39:07
问题 I have a middle tier which performs CRUD operations on a shared database. When I converted the product to .NET Core I thought I'd also look at using REST for the API as CRUD is supposed to be what it does well. It seems like REST is a great solution for single record operations, but what happens when I want to delete, say, 1,000 records? Every professional multi-user application is going to have some concept of Optimistic Concurrency checking: you can't have one user wipe out the work of

How to enable concurrency checking using EF 5.0 Code First?

房东的猫 提交于 2019-12-05 01:47:22
I would like to do a check-then-update in an atomic operation. I am using dbcontext to manage the transaction. I was expecting to get an exception if the record has been modified by another thread but no exception is thrown. Any help would be appreciated. Here's my output: Thread-4: Reading... Thread-5: Reading... Thread-5: Updating destination 1 Thread-4: Updating destination 1 Thread-4: SaveChanges Thread-5: SaveChanges Here's my code snippet: public static void Main(string[] args) { PopulateData(); (new Thread(UpdateDestination1)).Start(); (new Thread(UpdateDestination1)).Start(); } public

Solving Optimistic Concurrency Update problem with Entity Framework

*爱你&永不变心* 提交于 2019-12-04 19:01:40
How should I solve simulation update, when one user updates already updated entery by another user? First user request 'Category' entityobject, second user does the same. Second user updates this object and first user updates. I have field timestamp field in database that wa set to Concurrency Mode - Fixed. This is how I update: public class CategoriesRepository : BaseCategoryRepository { public void Update(....) { try { Category catToUpdate = (from c in Contentctx.Categories where c.CategoryID == categoryId select c).FirstOrDefault(); catToUpdate.SectionReference.EntityKey = new System.Data

RESTful API and bulk operations

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 05:58:14
I have a middle tier which performs CRUD operations on a shared database. When I converted the product to .NET Core I thought I'd also look at using REST for the API as CRUD is supposed to be what it does well. It seems like REST is a great solution for single record operations, but what happens when I want to delete, say, 1,000 records? Every professional multi-user application is going to have some concept of Optimistic Concurrency checking: you can't have one user wipe out the work of another user without some feedback. As I understand it, REST handles this with the HTTP ETag header record.

Concurrency exceptions in Entity Framework

拟墨画扇 提交于 2019-12-03 20:43:05
问题 When calling SaveChanges / SaveChangesAsync in Entity Framework (CF, C#), if a change conflict occurs (for example, the values has been updated since last read thingy), then which of these two exceptions DbUpdateConcurrencyException OR OptimisticConcurrencyException shall I catch? And what is the difference between them? 回答1: DbUpdateConcurrencyException is a specific exception thrown by DbContext , so this is the one to catch. This exception may be caused by an underlying

How can i force the DbUpdateConcurrencyException to be raised even if i am passing the FormCollection to my Post action method instead of an object

你离开我真会死。 提交于 2019-12-02 08:13:48
i have the following action method inside my asp.net mvc web application , which will raise a DbUpdateConcurrencyException as intended to handle any concurrent conflicts that might happen:- [HttpPost] public ActionResult Edit(Assessment a) { try { if (ModelState.IsValid) { elearningrepository.UpdateAssessment(a); elearningrepository.Save(); return RedirectToAction("Details", new { id = a.AssessmentID }); } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Assessment)entry.Entity; ModelState.AddModelError(string.Empty, "The record you attempted to