Sam

Sam

  • 1.5k
  • 221
  • 7.1k

Duplicate Record is inserting in DB in ASP.NET WEB API

Nov 28 2019 5:21 AM
While concurrent request is hitting to API it started to save duplicate record rather than checking condtion of duplicate record
 
I am sharing you my code
 
if (!db.dbMySampleDataSummary.Any(w => w.userid == id && w.clientId == tokenId))
{
MySampleDataSummary mySampleData = new MySampleDataSummary();
mySampleData.userid = id;
mySampleData.clientId = tokenId;
mySampleData.remarks = "remarks here for testing";
mySampleData.mobile = "0123456789";
mySampleData.approvedBy = "test user";
mySampleData.approvalStatus = true;
mySampleData.approvalDate = "2019-11-28";
mySampleData.isListed = true;
db.dbMySampleDataSummary.Add(mySampleData);
db.SaveChanges();
}
 

Answers (11)