Cannot implicitly convert type 'System.Linq.IQueryable' to 'int?'

前端 未结 6 1878
梦毁少年i
梦毁少年i 2021-02-06 23:14
var cityList = from country in 
                    doc.Element(\"result\")
                    .Element(\"cities\")
                    .Descendants(\"city\")
select ne         


        
6条回答
  •  忘掉有多难
    2021-02-06 23:42

    Here is the problem and solution

    from cnt in db.Countries where cnt.DOTWInternalID == citee.CountryCode select cnt.ID part. If you omit the ID then it returns a Generic IEnumerable with Country(hoping that you have Country class). So what you have to do is first return the select criteria and select the first row then the ID field. Same like shown below.

    cit.CountryID = (from cnt in db.Countries where cnt.DOTWInternalID == citee.CountryCode   select cnt).First().ID;
    

    This will solve your problem.

提交回复
热议问题