Entity Framework Caching Issue

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

    EF will not load changes unless you re query the context. EF queries db and loads maps them into objects, it watches changes you perform on objects and not on the database. EF does not track changes made directly to database and it will never track.

    You have loaded a List, that List is your cache in memory. Even calling Save Changes will not refresh. You will have to query the context once again, that is create new list.

    To see changes You will have to execute following line once more,

    datamodel.Compliances.Where(c => c.School.DistrictId == districtId).ToList()
    

提交回复
热议问题