Hi there,
I would like to make one database call to retrieve the following data, but I'm struggling to figure out what the LINQ should look like. Here's my current implementation (I know it's bad!!):
var photos = from photo in entitiesContext.Photo
join pg in entitiesContext.PhotoGallery on photo.PhotoGallery.PhotoGalleryID equals pg.PhotoGalleryID
where pg.PhotoGallery == photoGalleryID
select photo;
var photoList = photos.ToList();
foreach (var photoForLoading in photoList)
{
photoForLoading.UserReference.Load();
photoForLoading.PhotoComments.Load();
foreach (var comment in photoForLoading.PhotoComment)
{
comment.UserReference.Load();
}
}
return photoList;
So as you can see above I want to retrieve:
- All the photos from a specific photo gallery:
- The user details on each photo
- The comments on each photo
- The user details on each comment
How do I do this in LINQ with ADO.NET Entities Framework?
Cheers, Ash.