【发布时间】:2019-06-14 07:47:26
【问题描述】:
我是 LINQ / Entity Framework 的新手,我正在努力如何加入我的表。
我有以下课程:
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
}
所以一个PhotoPlace有多个ParkingLocation,一个ParkingLocation有多个ShootingLocation,一个ShootingLocation 有多张照片。
我现在想读取一个包含所有依赖对象的 PhotoPlace: 在我添加照片之前,以下语句一切正常:
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();
}
其他类应该无关紧要。我试图扩展
.Include(pp => pp.ParkingLocations.Select(pl => pl.ShootingLocations))
带有另一个“选择”的语句,但这不起作用。非常欢迎任何帮助。
【问题讨论】:
-
感谢您的提示 - 我想这涵盖了上面的以下行: Include(pp => pp.ParkingLocations.Select(pl => pl.ShootingLocations)) 但是,我想知道如何包含另一个加入(ShootingLocations 有照片,所以它是双重的 ThenInclude...
标签: c# entity-framework linq join