I am trying to insert duplicate record using EF by below code
db.Set<TEntity>().AddRange(lstEntity);
db.SaveChanges();
lstEntity
is a list of type TEntity
.
Suppose, I have 6 elements in lstEntity
, 3 of them are duplicate.
On the first line in AddRange
it only adds 4 elements, because 3 elements were duplicate so it adds 1 (3 duplicated) + 3 distinct records so it becomes 4.
And therefore, it inserts only 4 records in the DB.
I need to allow this duplicate thing and want to insert all the 6 elements (duplicate and distinct both).