How to Convert DBContext Object to ObjectContext in C# ?

Below is a function that converts the DBContext object to ObjectContext in C#.

How to Convert DBContext Object to ObjectContext in C# ?

public static ObjectContext ConvertContext(DbContext db)
{
   return ((IObjectContextAdapter)db).ObjectContext;
}