Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Replace</p> <p><code>public virtual List&lt;Wheel&gt; Wheels { get; set; }</code></p> <p>with</p> <p><code>public virtual ICollection&lt;Wheel&gt; Wheels { get; set; }</code></p> <p>This way EntityFramework will understand this as a Lazy-loaded child list and won't populate with values until needed.</p> <p>By using LinqToEntities, you can retrieve only the keys into a new list, like:</p> <pre><code>public virtual List&lt;int&gt; WheelIDs { get { return Wheels.Select(_w =&gt; _w.Id).ToList(); } } </code></pre> <p>This won't load the Wheels list but will return only their ID's for your.</p> <p>Remember that this is just a guess. You're needs might change, you might need to avoid DB hit everytime to check for wheels ID's and all, but this should help you find your way.</p> <h3>EDIT: some code to show better usage of IQueryable here...</h3> <pre><code>{ using(var context = new MyContext()) { // Doing this the wheel collection WON'T GET LOADED var cars = context.Cars; } using(var context = new MyContext()) { // Doing this the wheel collection WILL get loaded var cars = context.Cars.Include(_c =&gt; _c.Wheels); } using(var context = new MyContext()) { // Doing this also gets the wheel collection loaded // But this time, it will retrieve wheel-by-wheel on each loop. var cars = context.Cars; foreach(var car in cars) { foreach(var wheel in wheels) { /* do something */ } } } using (var context = new MyContext()) { // Doing this will get your id's without loading the entire wheel collection var cars = context.Cars; var wheelsIDs = cars.Wheels.Select(_w =&gt; _w.Id).ToList(); } using (var context = new MyContext()) { // Doing this will return every wheel for your car. // This improves performance over the other that retrieves wheel-by-wheel. var cars = context.Cars; foreach(var car in cars) { var wheels = car.Wheels.ToList(); } } } </code></pre>
 

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