EF 4.3 AddOrUpdate Method

When I moved to Entity Framework Migrations, I got caught out a little bit by the AddOrUpdate method that was introduced.

For a given table I was using this method in the initializer I had written to populate a table on creation. However, when publishing new versions of the application once the model had been modified I found myself to be quite perplexed to why it kept adding duplicate entries to this table.

After reading the article from Julie Lerman I learnt the lookup to check if a record exists or not is done by the first parameter passed in, which you would usually expect to be the Id. At this point I realized in this initializer only I had not specified the Id value for each record I wanted adding upon a data re-seed…