locked
EF inserting into Many To Many table RRS feed

  • Question

  • User1144600762 posted

    I am getting a duplicate key value error while inserting list items into a bridge table.

    The records are added, but will generate an duplicate key value error on the dbContext.SaveChanges();  method.

    How can I prevent this error?  many thanks for any help.

    foreach (MyType li in listitems)
    {
    dbContext.TableName.Add(li);
    }

    dbContext.SaveChanges(); 

    Friday, April 1, 2016 10:14 PM

Answers

All replies