Refreshing Data Using Entity Framework

前端 未结 2 640
慢半拍i
慢半拍i 2020-12-06 02:41

I\'m trying to use Entity Framework to query database and I have following code that I\'m using to get some data.

var students= MyEntities.Students.Where(s =         


        
2条回答
  •  一生所求
    2020-12-06 02:54

    No it never worked. This is essential behavior of entity framework (and many ORM tools) called identity map (explanation here).

    If you run the query on the same context you will not get your entities updated. It will only append new entities created in the database between running those two queries. If you want to force EF to reload entities you must do something like this:

    ObjectQuery query = MyEntities.Students;
    query.MergeOption = MergeOption.OverwriteChanges;
    var students = query.Where(s => s.Age > 20).ToList();
    

提交回复
热议问题