How to force Entity Framework to always get updated data from the database?

前端 未结 5 1884
[愿得一人]
[愿得一人] 2020-12-07 21:44

I am using EntityFramework.Extended library to perform batch updates. The only problem is EF does not keep track of the batch updates performed by the library. So when I que

5条回答
  •  难免孤独
    2020-12-07 22:31

    Making the code run on the same context will not yield you updated entities. It will only append new entities created in the database between runs. EF force reload can be done like this:

    ObjectQuery _query = Entity.MyEntity;
    _query.MergeOption = MergeOption.OverwriteChanges;
    var myEntity = _query.Where(x => x.Id > 0).ToList();
    

提交回复
热议问题