开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜