Entity Framework Caching Issue

后端 未结 12 2208
無奈伤痛
無奈伤痛 2020-12-08 00:19

I am new to Entity Framework.

I have get to some values in my database using EF. It returns perfectly, and the values are shown in labels. But When I delete all valu

12条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 00:39

    I think you should follow some of the other solutions here, but it seems like you're wanting to clear the cache. You can achieve this by doing the following:

    var count = datamodel.Compliances.Local.Count; // number of items in cache (ex. 30)
    
    datamodel.Compliances.Local.ToList().ForEach(c => {
        datamodel.Entry(c).State = EntityState.Detached;
    });
    
    count = datamodel.Compliances.Local.Count; // 0
    

提交回复
热议问题