title: How to use a virtual property when initializing anonymous type Entity Framework
body: <p>When trying to seed my database I am using the anonymous type like this:</p>
  
  <pre><code>context.CalibrationTargets.AddOrUpdate(x =&gt; new { calId = x.CalibrationSetup.Id, targetIndex = x.TargetIndex },
              new CalibrationTarget()...
  </code></pre>
  
  <p>However because <code>CalibrationSetup</code> is a virtual property I seem to get the error:</p>
  
  <blockquote>
    <p>The properties expression <code>x =&gt; new &lt;&gt;f__AnonymousType102(calId = x.CalibrationSetup.Id, targetIndex = x.TargetIndex)</code> is not valid. The expression should represent a property: C#: <code>t =&gt; t.MyProperty</code>  VB.Net: <code>Function(t) t.MyProperty</code>. When specifying multiple properties use an anonymous type: C#: <code>t =&gt; new { t.MyProperty1, t.MyProperty2 }</code> VB.Net: `Function(t) New With { t.MyProperty1, t.MyProperty2 } </p>
  </blockquote>
  
  <p>Also after reading this post <a href="https://stackoverflow.com/questions/20169376/the-properties-expression-is-not-valid-the-expression-should-represent-a-proper/34279425">The properties expression is not valid. The expression should represent a property</a>, the problem seem to be because of the fact that <code>CalibrationSetup</code> is a <code>virtual</code> property.</p>
  
  <p>Is there a way I can get around this without having to populate the database with another <code>Calibration_Id</code> column that isn't <code>virtual</code> to use in the anonymous type?</p>