Linq包含无法推断类型参数

时间:2014-06-17 13:45:25

标签: linq contains

 string[] companyIdsUnfiltered = companyIdsCsv.Split(',');

enter image description here

高于我的代码和我的错误。

Link to bigger picture

代码如下:

string[] companyIdsUnfiltered = companyIdsCsv.Split(',');
var query = (from c in ctx.Companies
             join co in ctx.Countries on c.CountryId equals co.Id
             where companyIdsUnfilteres.Contains(c.Id)
             select c.Id).ToArray();

1 个答案:

答案 0 :(得分:2)

鉴于错误,我猜解决方案是将c.Id转换为字符串。

var query = (from c in ctx.Companies
             join co in ctx.Countries on c.CountryId equals co.Id
             where companyIdsUnfilteres.Contains((string) c.Id)
             select c.Id).ToArray();

只是要添加,如果无法转换为string,请尝试c.Id.ToString()。并照顾空值等。