无法隐式转换类型'System.Linq.IQueryable< INT>'到'廉政?“ [英] Cannot implicitly convert type 'System.Linq.IQueryable<int>' to 'int?'

查看:1217
本文介绍了无法隐式转换类型'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

这篇关于无法隐式转换类型'System.Linq.IQueryable< INT>'到'廉政?“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆