I have Tasks
table: Id (PK), TaskName, Status
Status is one of: Queued, Busy, Complete.
I want to use multiple threads to process the tasks, and for that I need to be able to do in one operation:
var task = db.Tasks.FirstOrDefault(t=>t.Status == (byte) TaskStatus.Queued);
task.Status = (byte) TaskStatus.Busy;
db.SubmitChanges();
Obviously if operation is not atomic I can get concurrency issues. What is (if one exists) an intended way to do the above using Linq-to-Sql?
I know I can do that with 1) storproc or 2) db.ExecuteCommand("...")
or 3) handle the conflict with try/catch
- but I want to be sure there is no a better way.
I know it is a very basic question, but I wasn't able to find a definite answer to this.