Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement DBSet.AddOrUpdate in Entity Framework 4.4?

In response to Slauma's answer to my question about running applications that use EF on Windows XP I am converting my application back from Entity Framework 5.0 to use Entity Framework 5.0 and target framework .NET 4.0 (Also called Entity Framework 4.4)

However I encounter the following error;

System.Data.Entity.DbSet<MyEntity> does not contain a definition for AddOrUpdate 
and no extension method of a type System.Data.Entity.DbSet<MyEntity> accepting a 
first argument of type System.Data.Entity.DbSet<MyEntity> could be found.
(Are you missing a using directive or assembly reference )

I have tried searching on fragments of this error message, but am not having much success. Strangely 4.4 isn't even mentioned in this Microsoft link There isn't even an SO tag for EF4.4

like image 839
Kirsten Avatar asked Aug 01 '13 10:08

Kirsten


1 Answers

You must add...

using System.Data.Entity.Migrations;

...to your code file to have AddOrUpdate available. It is an extension method of IDbSet<T> that is implemented in the IDbSetExtensions class in System.Data.Entity.Migrations namespace.

like image 105
Slauma Avatar answered Oct 03 '22 21:10

Slauma