title: How to replace ObjectContext in Entity Framework Core 3.1
body: <p>I've been given the task of porting an project written with Entity Framework 6 to Entity Framework Core 3.1.</p>
  
  <p>I've done most of the job, but I can't find a solution for replacing ObjectContext. At the moment I'm facing this kind of problem:</p>
  
  <pre><code>    public static T FromObjectToStruct&lt;T&gt;(object o) where T : struct
      {
          // Cast the value read to type choice
          return (T) (o as T?).GetValueOrDefault();
      }
  
  
      /// &lt;summary&gt;
      /// Convert an object to a dictionary
      /// &lt;/summary&gt;
      /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
      /// &lt;param name="obj"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static Dictionary&lt;string, object&gt; ToDictionary&lt;T&gt;(this T obj) where T : class
      {
          var dictionary = new Dictionary&lt;string, object&gt;();
          var properties = ObjectContext.GetObjectType(obj.GetType()).GetProperties(
              BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy);
          foreach (var p in properties)
          {
              dictionary.Add(p.Name, p.GetValue(obj, null));
          }
  
          return dictionary;
      }
  
      /// &lt;summary&gt;
      /// Returns the differences between two objects of the same type T
      /// &lt;/summary&gt;
      /// &lt;param name="obj1"&gt;&lt;/param&gt;
      /// &lt;param name="obj2"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static Dictionary&lt;string, object&gt; GetDiff&lt;T&gt;(this T obj1, T obj2) where T : class
      {
          var diff = new Dictionary&lt;string, object&gt;();
          var objType = ObjectContext.GetObjectType(obj1.GetType());
          var objProperties = objType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic |
                                                    BindingFlags.Public | BindingFlags.FlattenHierarchy);
  
          foreach (var objProperty in objProperties)
          {
              var objValue1 = objProperty.GetValue(obj1, null);
              var objValue2 = objProperty.GetValue(obj2, null);
              if (!Equals(objValue1, objValue2))
              {
                  diff.Add(objProperty.Name, objValue2);
              }
          }
  
          return diff;
      }
  </code></pre>
  
  <p>Any hint or link to documentation that explains how to workaround the issue would be great.</p>