tags:

views:

26

answers:

0

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 = this.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