1

I have a list of updated objects. And I tried to update all records with only one database call.(one context.SaveChanges() command). This programme runs inside a windows service. My problem is instead of updating I am multiplicating all records on the database and adding duplicates. Following is my code.

//adding the list of updated customer objects to the list
context_CLTUS.Customer_Updates.AddRange(list.customerUpdateList);
foreach (var j in list.customerUpdateList) 
{
    //calling entity state modify for each record
    context_CLTUS.Entry(j).State = EntityState.Modified;
}
//save updated list in one db call.
context_CLTUS.SaveChanges();

I cannot clarify why all records are duplicating instead of updating. Could you please explain and help me on this. Thank you.

thilanka1989
  • 77
  • 15

1 Answers1

1

Refer to this answer

You can try these solutions :

  1. Swap update operation in a TransactionScope.

  2. Set Configuration.AutoDetectChangesEnabled = false.

  3. Try Entity Framework Plus, a high-performance enhancement library.

Nico
  • 390
  • 8
  • 20
  • Tried Entity Framework Plus for the first time , Saved my time! thank you! – thilanka1989 Jul 15 '17 at 16:14
  • @thilanka1989 sorry for my misunderstanding, and in your case, maybe the comments above are easier, thanks for your vote too. – Nico Jul 16 '17 at 04:36