Turn Off Object Caching in Entity Framework CTP5

狂风中的少年 提交于 2019-11-30 16:52:54

问题


I am having trouble figuring out something with the Entity Framework Code First stuff in CTP 5. It is doing caching of objects and I don't want it to. For example, I load a page (working with an ASP.NET MVC site) which loads an object. I then go change the database. I re-load the page and the changes are not reflected. If I kill the site and rerun it then it obviously re-fetches. How do I, either generally for a type, or even for a particular query, tell it to always go get a new copy. I think it might have something to do with MergeOption but I'm having trouble finding examples that work with CTP 5. Thanks.


回答1:


Okay, figured it out. The following will sometimes pull from the EF cache:

return (from m in _dataContext.Monkeys
        where m.MonkeyId == monkeyId
        select m).FirstOrDefault();

You can use AsNoTracking() to bypass the change tracking/caching stuff:

return (from m in _dataContext.Monkeys.AsNoTracking()
        where m.MonkeyId == monkeyId
        select m).FirstOrDefault();


来源:https://stackoverflow.com/questions/4911000/turn-off-object-caching-in-entity-framework-ctp5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!