To obtain a position and eagerly load each of its quotes and quoteitems, you type:
var job = db.Jobs .Include(x => x.Quotes.Select(q => q.QuoteItems)) .Where(x => x.JobID == id) .SingleOrDefault();
You could require
in place of
whether QuoteItems is also a collection.
Observation for others: The boldfaced
since method is an extension method, you must
in the file's header.
Given that we are talking about an entity framework and you wish to fetch child entities, the following will work:
var job = db.Jobs .Include(x => x.Quotes) // include the "Job.Quotes" relation and data .Include("Quotes.QuoteItems") // include the "Job.Quotes.QuoteItems" relation with data .Where(x => x.JobID == id) // going on the original Job.JobID .SingleOrDefault(); // fetches the first hit from db.
For additional details regarding the
look at this statement: http://msdn.microsoft.com/en-us/library/bb738708(v=vs.110).aspx
Try https://stackoverflow.com/a/24120209/691294 first, as this answer has received many upvotes throughout the years. I just wanted to make that clear. This remedy is for situations where all else has failed and you must turn to a black magic fix (i.e. using magic strings).