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

前端 未结 2 1708
情话喂你
情话喂你 2021-02-19 08:26

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 Entit

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-19 08:43

    When you enable migrations for MVC5 web applications, you get the following comment in the Seed method of the configuration:

    //  You can use the DbSet.AddOrUpdate() helper extension method 
    

    My initial stab at this was to user DbSet.AddOrUpdate(). This will lead to the same error message (and rightly so) as the one raised in this question. The fix is to read the rest of the comment and use the context parameter passed into the Seed function:

        context.MyEntity.AddOrUpdate();
    

提交回复
热议问题