The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

tophog (1) [Avatar] Offline
#1
I have a scenario similar to the Northwind Customer -> Orders -> OrderDetails relationship where I want to load the data in all 3 entities immediately for a specific customer and where the OrderDetails match specific criteria.

Here is my original post but haven't received any help yet.

http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/b7aa32f2-dc4e-4509-8e5d-173bd9a1e0a0

At this point I can load the OrderDetail records I want however all Order records are being returned even if they have no matching OrderDetail records for the given year.

Here is the code I am using. It would seem I need to tell the query to not return Order records that have no matching OrderDetail records.

Dim dlo As New DataLoadOptions()

dlo.LoadWith(Of aspnet_User)(Function(c As aspnet_User) c.aspnet_Role)
dlo.LoadWith(Of aspnet_User)(Function(c As aspnet_User) c.Requests)
dlo.LoadWith(Of Request)(Function(o As Request) o.RequestDetails)
dlo.LoadWith(Of Request)(Function(o As Request) o.StatusType)
'dlo.AssociateWith(Of Request)(Function(u As Request) u.RequestDetails.Contains(u.RequestId))

dlo.AssociateWith(Of Request)(Function(r As Request) r.RequestDetails.Where(Function(x) x.VacationDate.Year = intYear))


Me.LoadOptions = dlo

Dim query = From u In aspnet_Users _
Where u.aspnet_Role.LoweredRoleName = primaryRole.ToLower _
And u.AccountHidden = False _
Order By u.LoweredUserName _
Select u


Return query.ToList