Using IQToolkit with MySQL, I would like to perform a LOCKING READ within a transaction and according to the mysql docs, the way to do that is by using “SELECT… FOR UPDATE”.
However it seems that LINQ does not support this by default and I found this thread talking about achieving similar goal by handling the ChangeConflictException. what is the best way to do the same using IQToolkit LINQ provider with MySQL?
Using IQToolkit with MySQL, I would like to perform a LOCKING READ within a
Share
IQToolkit doesn’t have a facility to request row locking. However, if you are using a transaction you ought to get read locks for reads happening within the transaction, depending on the level of isolation of the transaction.
LINQ to SQL has specific support for optimistic concurrency, meaning the expected use of the API’s is that you don’t read the data within a transaction, but when you submit changes, all those go within a transaction (which happends under the covers on your behalf.) The optimistic part occurs when the updates are sent. If the rows have changed since when you read the data, the updates for those rows will fail. This leaves you with the choice of either aborting the whole thing, automatically starting over with new reads, etc, or using the information in the change conflict exception to pick and chose which how to merge your changes with the databases changes and then resubmit them. The pick and chose approach is complicated and unless you ‘know what you are doing’, you should probably just use the ‘retry the whole thing from scratch’ approach.
IQToolkit does not have the facility to enable you to use the ‘pick and choose and resubmit’ approach. So you are best served, if attempting optimistic concurrency, to simply retry the whole thing if an update fails. If you would rather use pessimistic concurrency and simply putting the read queries under the transaction does not give you the lock you want, then you are free to add that capability to IQToolkit as it is fundementally a source kit and examples for building IQueryable query providers.