help help Why is Entity Framework 5.0 inserting duplicate records in the Database in uncertain behavior when using AddAsync() method for adding data. enter image description here
CodePudding user response:
You are checking for null
in your list. However a .Where()
query will return an empty enumerable and not null when it doesn't find any results.
To fix this issue you have to check the count.
var exist = await context.Where(x => x...)
if(exist == null || exist.Count() == 0)
{
add purchase here
}
CodePudding user response:
The problem here is that the AddAsync function sends two records to the database for registration