I am new with LINQ / Entity Framework and I am struggling how to join my tables.
I have following classes:
public class PhotoPlace
{
#region attributes
[Key]
public long Id { get; set; }
public List<ParkingLocation> ParkingLocations { get; set; }
public SubjectLocation PlaceSubjectLocation { get; set; }
#endregion
#region constructors
public PhotoPlace()
{
}
#endregion
}
public class ParkingLocation : LocationBase
{
#region attributes
public PhotoPlace PhotoPlace { get; set; }
public List<ShootingLocation> ShootingLocations { get; set; }
#endregion
public ParkingLocation()
{
}
}
public class ShootingLocation : LocationBase
{
#region attributes
public ParkingLocation ParkingLocation { get; set; }
public List<Photo> Photos { get; set; }
#endregion
#region constructors
public ShootingLocation()
{
}
#endregion
}
public class Photo
{
#region attributes
public long Id { get; set; }
public byte[] ImageBytes { get; set; }
public ShootingLocation ShootingLocation { get; set; }
#endregion
#region constructors
public Photo()
{
}
#endregion
}
So a PhotoPlace has multiple ParkingLocations, a ParkingLocation has multiple ShootingLocations, a ShootingLocation has multiple Photos.
I now want to read a PhotoPlace with all dependent objects: Before I added the Photos, everything was fine with the following statement:
using (var db = new LocationScoutContext())
{
photoPlacesFound = db.PhotoPlaces.Include(pp => pp.PlaceSubjectLocation)
.Include(pp => pp.ParkingLocations.Select(pl => pl.ShootingLocations))
.Include(pp => pp.PlaceSubjectLocation.SubjectCountry)
.Include(pp => pp.PlaceSubjectLocation.SubjectArea)
.Include(pp => pp.PlaceSubjectLocation.SubjectSubArea).ToList();
}
The other classes should not matter. I tried to extend the
.Include(pp => pp.ParkingLocations.Select(pl => pl.ShootingLocations))
statement with another "Select" but that does not work out. Any help is very welcome.