linq to entities - "Next number" scenarios using Entity Framework -
i have been playing entity framework , far using lot. i've done far assumes optimistic locking works me in cases. however, have following scenario:
- a sql server table 1 row holds application-wide data
- the row contains column named "nextavailablenumber"
- the application needs read number, increment 1, , update it
the above has guarantee competing process has wait number until first transaction has completed. have done using table locks (since there's 1 row), know how should done using linq entities?
thanks,
jim k.
i think need implement in stored procedure because , use explicit row locking (or table locking mentioned). call procedure ef. don't think can handled application code unless using serializable transaction every time work special table. can have huge negative impact on application's performance.
we doing similar our table contains plenty of rows different sequences i'm using stored procedure row lock , update lock. first wanted call procedure in insert method of our repository after moved database , call procedure after insert trigger. reason deffer row locking time of real insertion database not time of marking entity insert in ef context (insert , procedure call must in same transaction in our case). modified ef model related property has storegeneratedpattern set computed. after each insert ef requery db assigned sequence number. drawback ef requery db after each update of these entities in our case because of timestamp. still in phase of testing , evaluating can still change mind , reimplement it.
Comments
Post a Comment