I work with Entity Framework - add records in the database using classes that map to the DB. But i need to make sure I dont add duplicate records in the database. I assumed that when SaveChanges() is called, it sorts out all the duplicates, but it doesnt. Is there a way to eliminate creation of the duplicate records?
+3
A:
It's the DB's job to detect and block duplicates, because the ObjectContext may not/probably won't have all records in memory, so it can't reliably stop duplication.
So if you don't already have a UNIQUE constraint in your DB, you need to add one.
Craig Stuntz
2009-10-30 12:45:55