Is it possible to load child entities in a single query without using DataLoadOptions?
I am using one data context per request in an asp.net web application and trying to get around the linq to sql limitation of not being able to change dataloadoptions once a query has been executed.
Thanks.
If you don't mind the link to the data context, as you say you don't, you could write a stored procedure that returns multiple results that map to your objects. Read more about it here.
I found the following vb.net example which manually populates child entities from an IMultipleResults type:
Public Function GetSubjectsWithBooks() As List(Of Subject)
Dim results As IMultipleResults = Me.GetSubjectAndBooks
Dim Subjects = results.GetResult(Of Subject).ToList
Dim Books = results.GetResult(Of Book).ToList
For Each s In Subjects
Dim thisId As Guid = s.ID
s.FetchedBooks = (From b In Books Where b.SubjectId = thisId).ToList
Next
Return Subjects
End Function
This was taken from a sample project written by Jim Wooley (one of the Link in Action authors) which can be found at:http://www.thinqlinq.com/Downloads/LinqToSqlBeyondTheBasics.zip
Omer, is this the technique you were referring to?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With