My WebAPI is successfully working in localhost (with UI in Angular and With postman as well) but when I am publishing it to the Azure server it starts throwing Optimistic Concurrency Exception when trying to update existing entity. Getting same exception even when I am connecting the Server DB using local visual studio 2019 and testing though postman.
This issue drives me crazy since last 3-4 weeks. I have confirm that each and every properties is binding correctly including foreign keys. And Server database has same table structure with all the key's as localhost.
I am using entity framework 6 with repository pattern, .Net framework 4.8, SQL Server 2017 (tried SQL Server 2014).
What I have tried to resolve issue but did not get luck :
- Set [ConcurencyCheck] to property
- make sure that no other thread is trying to change entity Or no other transaction is running
- disabled foreign keys and just updating single column of table
- I can able to insert new records in same table
- published database and API both to different server
- Try to refresh entity with Client wins (https://learn.microsoft.com/en-gb/ef/ef6/saving/concurrency?redirectedfrom=MSDN) and save changes again
I am out of idea now to resolve this issue. Does anyone face the same issue ? Or any configuration that I am missing or should I try ?
Please don't mark this question as duplicate, since I tried possible all the solutions i found in different threads.
[Edit] Sample Code :
// LeadCustomer is inheriting from baseclass ModelBase which has CreatedById, CreatedDate, ModifiedById, ModifiedDate properties
LeadCustomer leadCustomer = dc.LeadCustomers.Where(c => c.Email.EmailAddress.ToLower().Equals(model.EmailAddress.ToLower())).FirstOrDefault();
if (leadCustomer == null) {
leadCustomer.FirstName = "Viral";
leadCustomer.LastName = "Maru";
leadCustomer.Email.EmailAddress = "maru.viral@gmail.com";
leadCustomer.SubscriptionTypeID = SubscriptionTypes.Monthly;
dc.LeadCustomers.Add(leadCustomer);
dc.SaveChanges();
}