Entity Framework Caching Issue

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

    Firstly I would not suggest modifying the database external to your system unless you are only doing testing and development.

    The EF DbContext contains an IDisposable interface. To release any cached data either make the Dispose calls manually or place your Database Object inside a using block.

            using (SchoolBriefcaseEntities datamodel = new SchoolBriefcaseEntities())
            {
                List compliance = new List();
                IList complianceModel;
                if (HttpContext.Current.User.IsInRole("SuperAdmin"))
                {
                    compliance = datamodel.Compliances.Where(c => c.School.DistrictId == districtId).ToList();
                }
            }
    

    This will make sure the context is cleared and recreated the next time it is used. Make sure to do this for all your calls and not just the one you are having issues with.

提交回复
热议问题