0
var topTen = (from ep in db.VisitedCities
join c in db.Countries on ep.PersonWhoVisitedNationalityId equals c.CountryId
join e in db.Cities on ep.CityId equals e.CityId
join t in db.Countries on e.CountryId equals t.CountryId
where t.Name == "Portugal"
select ep.PersonWhoVisitedNationality).ToList();
这样做的结果返回一个列表与几个项目,但他们都是空的,即时我在这里失踪?如何让这个linq查询返回正确的值
我期待获得国籍的名单(他们是Country
型)
在此先感谢。
编辑:
好了,所以第一个问题是有关这一点,我想到底什么是这样的(工作,但只有当我把.ToList()
中间:()
var topTen = (from ep in db.VisitedCities
join e in db.Cities on ep.CityId equals e.CityId
join t in db.Countries on e.CountryId equals t.CountryId
where t.Name == "Portugal"
select ep)**.ToList()**
.GroupBy(x => x.PersonWhoVisitedNationality)
.Select(cp => new
{
CountryName = cp.Key,
NumberOfTravelers = cp.Count()
})
.OrderByDescending(x => x.NumberOfTravelers)
.Take(10)
.ToList();
注意,我用的是新的实体框架7,我觉得对于现在的包括extention还不所以夏季工作... 了此查询工作正常,但只有当.ToList()
在中间:(
你可以返回“C”,而不是“ep.PersonWhoVisitedNationality”。我认为它应该工作。 –