无法隐式转换类型'System.Linq.IQueryable< INT>'到'廉政?“

无法隐式转换类型'System.Linq.IQueryable< INT>'到'廉政?“

问题描述:

var cityList = from country in 
                    doc.Element("result").Element("cities").Descendants("city")
select new {
        Name = country.Element("name").Value,
        Code = country.Element("code").Value,
        CountryCode = int.Parse(country.Element("countrycode").Value)
    };

foreach(var citee in cityList)
{
    City city = new City();
    city.CountryID = from cnt in db.Countries 
             where cnt.DOTWInternalID == citee.CountryCode select cnt.ID;
}



作为标题看到我得到的第二个查询错误这个帖子。我试图转换为 INT 可空INT ,但毫无效果。帮帮我吧,伙计们。

I'm getting an error on the second query as seen in the title of this post. I tried converting to int to nullable int but nothing worked. Help me, guys.

感谢

这将返回IQueryable的,你需要做的是这样使用的第一个

it will return an iQueryable, you will need to do something like using the First

cit.CountryID = db.Countries.First(a=>a.DOTWInternalID == citee.CountryCode).ID