Note that there are some explanatory texts on larger screens.

plurals
  1. POAdvanced LINQ Query Help
    text
    copied!<p>So I have the following LINQ query:</p> <pre><code>var qryVans = from v in objContext.vans join s in objContext.schools on v.schoolID equals s.schoolID join l in objContext.locations on v.lastKnownLocationID equals l.locationID select new DisplayVan { vanID = v.vanID, vanName = v.vanName, phone = v.phone, capacity = (int)v.capacity, schoolName = s.schoolName, lastLocationName = l.locationName, statusNote = v.statusNote, isOffline = (v.isOffline == 1) ? true : false, isPrayerRoom = (v.isPrayerRoom == 1) ? true : false, isNotReady = (v.isNotReady == 1) ? true : false, creationDate = v.creationDate, modifiedDate = v.modifiedDate, vanAssignments = from a in v.vanAssignments where a.vanID == v.vanID select a }; </code></pre> <p>All works fine, except I'm needing to fill the navigation properties of the <code>VanAssignment</code> entity. Notice, in my <code>DisplayVan</code> projection, I am using a nested query to gather the van assignments for the given van. The <code>vanAssignment</code> entity has a person entity. So how would I load the <code>vanAssignment.person</code> property in this query?</p> <p>Also, could I write this to be more efficient?</p> <p>Thanks for your help!</p> <p><strong>EDIT</strong></p> <p>Here is where my code above fails:</p> <p>After I execute a toList() on the query above, I'll try to access the needed person like this:</p> <pre><code>List&lt;DisplayVan&gt; lstVans = qryVans.toList&lt;DisplayVan&gt;(); foreach(DisplayVan objVan in lstVans) { Console.WriteLine(objVan.person.firstName); } </code></pre> <p>Now, since I didn't load in the person entity with the vanAssignment entity, the person navigation property is null and it throws an error.</p> <p>My question centers around the correct way to load in this person entity along with vanAssignment?</p> <p>Hope that helps.</p>
 

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