我有以下linq查询:
var allLocationRates = (from homeLocation in clientLocations
from hostLocation in clientLocations
select new PaymentRateTrip
{
HomeCountryId = homeLocation.CountryId,
HomeCountry = homeLocation.CountryName,
HostCountryId = hostLocation.CountryId,
HostCountry = hostLocation.CountryName,
HomeLocationId = homeLocation.LocationId,
HomeLocation = homeLocation.LocationName,
HostLocationId = hostLocation.LocationId,
HostLocation = hostLocation.LocationName
}
into allLocations
from l in allLocations // <-- error on this line
// continues on...
我正在努力获得clientLocations
的所有可能组合。但是,在上面的查询中,我在行from l in allLocations
上收到错误。它写着:
后续版本中不允许使用“PaymentRateTrip”类型的表达式 源类型的查询表达式中的from子句 'System.Collections.Generic.IEnumerable'。类型 “SelectMany”调用中的推断失败。
为什么在选择列表时只选择一个PaymentRateTrip
?
答案 0 :(得分:1)
在select子句之后使用关键字into
时,您正在执行“查询继续”,这意味着所有后续的linq代码都在into
之后的名称上运行。你不需要“来自所有地方的l”这一行,只需在into
之后使用'l',如:
}
into l
// continues on...
// For example: select l.HomeCountryId