我正在尝试写一个查询,从我加入的数据中获取一个国家列表。Places是List<Country>。
var zonedCountries = (from dz in db.DeliveryZones.Include(d => d.Places)
where model.DeliveryZones.Contains(dz.ID)
select dz.Places);我希望zonedCountries是一个列表,但它却是一个IQueryable<ICollection<Country>>。
我该如何从中提取名单呢?
发布于 2014-01-15 15:24:51
如果您想得到一个国家的列表:
var zonedCountries = (from dz in db.DeliveryZones.Include(d => d.Places)
where model.DeliveryZones.Contains(dz.ID)
from p in dz.Places
select p);或者使用SelectMany
var zonedCountries = db.DeliveryZones.Include(d => d.Places)
.Where(dz => model.DeliveryZones.Contains(dz.ID))
.SelectMany(dz => dz.Places);顺便说一句,我不确定在本例中是否需要手动包含位置(因此您选择的是位置而不是交付区域)。而且您可能只想选择不同的国家- Distinct()将在这里帮助您。另外,如果您想将结果存储在列表中,那么简单的ToList()调用将完成这项工作。
https://stackoverflow.com/questions/21141365
复制相似问题