Click here to Skip to main content
15,894,195 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using transaction scope in my project. Isolation level is IsolationLevel.ReadCommitted

i Also tried IsolationLevel.RepeatableRead


C#
using (DBOperations dboperation = new DBOperations())
    {
      GetAccountVoucherNuber();
    }


i am calling this method from Transaction Scope.

C#
private void GetAccountVoucherNuber() {

    var _dB0010013 = _dB0010013Repository.GetAll().Where(e = > e.Category == "D" && e.CategoryType == "TSNO" && e.Branch == Branch && EntityFunctions.TruncateTime(e.OnDate) == EntityFunctions.TruncateTime(TranInit.EntryDate) && e.CodeOne == BatchCode).FirstOrDefault();
    if (_dB0010013 == null) {
        _dB0010013 = new DB0010013();
        _dB0010013.Branch = Branch;
        _dB0010013.Category = "D";
        _dB0010013.CategoryType = "TSNO";
        _dB0010013.CodeOne = BatchCode;
        _dB0010013.CodeTwo = "";
        _dB0010013.CodeThree = "";
        _dB0010013.OnDate = TranInit.EntryDate;
        _dB0010013.Note = "";
        _dB0010013.LastNo = 1;

        var _operationStatus = _dB0010013Repository.AddAndSave(_dB0010013, false);
    } else {
        _dB0010013.LastNo += 1;
        var _operationStatus = _dB0010013Repository.UpdateAndSave(_dB0010013, false);
    }

}



when two or more user submits the page at same time.
i am getting same no for two transaction.


eg. suppose user1 got lastNo =85 +=1 =86

at the same time user2 also get lastNo =85 +=1 =86

so the same no is applied for two different transactions.


How Can i Lock Select Statement after getting values. or what is way to handle it.
i googled a lot but didnt find any solution.








Posted
Comments
coded007 5-Mar-15 3:02am    
Please can you post your transactions scope code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900