开发者

Linq-To-Sql ClearCache() Method - Ok to call?

开发者 https://www.devze.com 2022-12-30 22:31 出处:网络
I want to be able to clear the database context cache in order to clear the entities the context is currently tracking. The context object has a ClearCache method, but it\'s internal. I wrote the foll

I want to be able to clear the database context cache in order to clear the entities the context is currently tracking. The context object has a ClearCache method, but it's internal. I wrote the following code to call this method:

private void ClearContextCache()
{
    const BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
    var method = th开发者_JAVA百科is.GetType().GetMethod("ClearCache", FLAGS);
    method.Invoke(this, null);
}

The method works fine. But I'm concerned about whether clearing the context cache is a safe thing to do. I assume there is a reason why the L2S architects at Microsoft didn't want developers calling this method. Anyone have experience with this?

Thanks - Randy

0

精彩评论

暂无评论...
验证码 换一张
取 消