Entity Framework Caching Issue

后端 未结 12 2205
無奈伤痛
無奈伤痛 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:48

    Couple things you can do.

    1. Use a new context. The cached entities are stored in the context. Using a new context prevents it from using the cache.
    2. If you really want a global/long lasting context, you have two sub options: a.) always call the Reload method. db.Entry(entity).Reload() ... this forces the context to reload that entity. b.) use a SqlDependency object to detect when records change and reload the entities as needed. https://code.msdn.microsoft.com/How-to-use-SqlDependency-5c0da0b3

提交回复
热议问题