In the Entity Framework (in particular, EF 3.5, but if it exists in EF 4, this gives me a reason to update), is it possible to lazy the load on only part of the collection? Perhaps I am also approaching this wrong, so I am open to suggestions. My tables / entities look something like this:
Person PersonMeal Meal ------ 1---* ---------- *---1 ----- ID ID ID ... PersonID ... MealID Value ...
I have a list of Person objects that were obtained through the Entity Framework through a stored procedure. I have a view that shows only one Meal at a time, so I only need the information related to this meal. I currently have code that looks like this:
Function GetPersons() As List(Of Person) Dim personList = context.StoredProcedureCall(param1, param2, param3).ToList() personList.ForEach(Function(x) LazyLoadProperties(x)) Return personList End Function ' Work around function because VB lambdas don't take Sub's Function LazyLoadProperties(ByVal person As Person) As Object If (Not person.PersonMeal.IsLoaded) Then person.PersonMeal.Load() End If Return Nothing End Function
The problem is loading the entire collection. Provided this is a small collection, so in the worst case, I can download it all and then delete everything except what I need, but it is far from ideal. Plus, I'm not sure that this would be possible without causing any collection change events, since they should not have been there in the first place.
Agent_9191
source share