I'm having a problem using UpdateModel(theModelToUpdate) causing concurrency issues.
Basically whats happening is, there is a row in the database that contains most but not all the information needed for that row. The rest of the needed information is NULL. The user (using a listbox) would then add information to this row, as well as creating new rows (An ajax command is sent for every item in the listbox. So the controller is being called very fast because of the loop used to get the items).
In my controller I first check to see if the columns the user will be updating are NULL. If they are, I use UpdateModel to update the row. If they are not null (meaning the row is complete ) then I create new rows with the remaining listbox items.
开发者_如何学PythonWhen debugging, I notice that since the controller is called so quickly, the UpdateModel isn't called right away like I had planned. Several items from the listbox get skipped because of this and I get an error saying the row cannot be updated.
How can I solve this?
Not sure I got this right: When is the controller invoked using AJAX? You say this happens very fast, so I assume you invoke the controller multiple times on submit, rather than every time the user actually adds a row. Under "very fast" I understand multiple operations per second.
Well, for once I think you shouldn't use UpdateModel
if you merely add an entry to a row - you could do this manually.
Second, invoking the controller on the same item in fast succession might indeed lead to concurrency issues on the database because it has to acquire a lock somewhere. However, I think this will depend on your database abstraction, the database type and the locking mechanism you use.
I'd suggest you write a small controller action that only adds a single entry interactively, i.e every time the user actually does something. This should keep you from concurrency issues.
I resolved the issue by not using UpdateModel to update the row. Instead I Insert the rows, then go back and delete the row with the missing information. Probably not the best solution, but it fixed my problem.
精彩评论