好吧,它甚至不会编译为有效的 c#,但我认为你正在寻找的是这样的:
var results =
from j in job
from jp in j.JobParts
where j.CustomerID == 1
select new { jp.PickupAddress, jp.DestinationAddress };
假设您在JobParts
和之间设置了正确的导航属性,这将起作用Addresses
。
你可以很容易地使用它:
foreach(var record in results)
{
var pickupHouseNo = record.PickupAddress.HouseNo;
var pickupStreet = record.PickupAddress.Street;
// ...
var destinationHouseNo = record.DestinationAddress.HouseNo;
var destinationStreet = record.DestinationAddress.Street;
// do stuff
}
如果您真的希望它们作为平面查询结果,只需使用以下命令:
var results =
from j in job
from jp in j.JobParts
where j.CustomerID == 1
select new
{
PickupHouseNo = jp.PickupAddress.HouseNo,
PickupStreet = jp.PickupAddress.Street,
// ...
DestinationHouseNo = jp.DestinationAddress.HouseNo ,
DestinationStreet = jp.DestinationAddress.Street,
};