Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand you right, EF generates something like</p> <blockquote> <pre><code>class YourStudent { public int studentId { get; set; } public string name { get; set; } public string lastName { get; set; } public virtual ICollection&lt;Course&gt; Courses { get; set; } } </code></pre> </blockquote> <p>and there is</p> <pre><code>class TheirStudent { public int studentId {get;set;} public string name { get; set; } public string lastName { get; set; } } </code></pre> <p>and you want to stuff values from a TheirStudent instance into a YourStudent instance.</p> <p>Maybe something like</p> <pre><code>YourStudent s1; TheirStudent s2; Type t = typeof(YourStudent); Type t2 = typeof(TheirStudent); foreach (PropertyInfo pinfo in t.GetProperties()) { if (pinfo.GetGetMethod().IsVirtual &amp;&amp; pinfo.PropertyType.IsGenericType &amp;&amp; pinfo.PropertyType.GetGenericTypeDefinition() == typeof(ICollection&lt;&gt;)) { // This is [probably] a nav property. Courses would be in here } else if (pinfo.GetGetMethod().IsVirtual) { // if you have 0..1 or 1..1 nav properties you might muck around in here } else if (!pinfo.GetGetMethod().IsVirtual) { // This is [probably] a column - studentId, name, etc would be here // you could pull values over like so: PropertyInfo pinfo2 = (from ps in t2.GetProperties() where ps.Name == pinfo.Name select ps).SingleOrDefault(); if (pinfo2 != null) { object value = pinfo2.GetValue(s2, new object[] { }); pinfo.SetValue(s1, value, new object[] { }); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload