title: Copy Properties of one object to another object
body: <p>Relate to : <a href="https://stackoverflow.com/questions/12881866/set-properties-that-not-null-using-linq-and-reflection/12881949#12881949">Set Properties that not null using linq and reflection</a></p>
  
  <p>Hi experts</p>
  
  <p>I change the code in above link:</p>
  
  <pre><code>public static void MyCopy&lt;T&gt;(this T src, T dest)
  {
      var notNullProps = typeof(T).GetProperties()
                                  .Where(x =&gt; x.GetValue(src, null) != null);
  
      foreach (var p in notNullProps)
      {
          p.SetValue(dest, p.GetValue(src, null),null);
      }
  } 
  </code></pre>
  
  <p>and I wrote this code to copy peroperties:</p>
  
  <pre><code>NorthwindModel1.Order ord1 = new NorthwindModel1.Order() {CustomerID="Nima",Freight=1.33m,ShipCity="Agha" };
  NorthwindModel1.Order ord2 = new NorthwindModel1.Order() ;
  
  ord1.MyCopy(ord2);
  </code></pre>
  
  <p>but I got this error:</p>
  
  <blockquote>
    <p>The EntityReference has already been initialized. InitializeRelatedReference should only be used to initialize a new EntityReference during deserialization of an entity object. </p>
  </blockquote>
  
  <p>please help me to solve this problem</p>