I have this query below but I'm not sure how to write the query so that I don't have to loop through each yogaSpace and run an individual query.
I'd like to run it all at once in one query. FYI - yogaprofile has a one to many with yogaspaces. yogaspaces has a one to many with yogaspaceevents. And I want all the yogaspaceevents from all the yogaspaces from a single yogaprofile.
using (var dbContext = new YogabandyContext())
{
var yogaProfile = dbContext.YogaProfiles.Where(i => i.ApplicationUserGuid == userId).First();
var yogaSpaces = yogaProfile.YogaSpaces;
var today = DateTime.Now.Date;
foreach (var yogaSpace in yogaSpaces)
{
var yogaEvents = yogaSpace.YogaSpaceEvents.Where(k => k.EventDateTime.Date > today.AddDays(-30) && k.EventDateTime < today.AddDays(30));
// do something with the yogaEvents here
}
}