How to clear the DataContext cache on Linq to Sql

后端 未结 3 1744
南旧
南旧 2020-12-28 08:40

I\'m using Linq to Sql to query some database, i only use Linq to read data from the DB, and i make changes to it by other means. (This cannot be changed, this is a restrict

3条回答
  •  一向
    一向 (楼主)
    2020-12-28 09:17

    I made this code to really CLEAR the "cached" entities, detaching it.

    var entidades = Ctx.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Deleted | EntityState.Modified | EntityState.Unchanged);
    foreach (var objectStateEntry in entidades)
        Ctx.Detach(objectStateEntry.Entity);
    

    Where Ctx are my Context.

提交回复
热议问题