Linq to sql 使用';包含';和一个INT列。你是怎么做到的?

Linq to sql 使用';包含';和一个INT列。你是怎么做到的?,linq-to-sql,Linq To Sql,我正在尝试让LINQ to SQL正常工作。问题是parsedSeasons是一个类似“1,2,3”的字符串,h.season是一个int列。我怎样才能让它正常工作 var id = (from h in db.t_ref_harvest_type where parsedSeasons.Contains(h.season) select new { h.id }); 您需要先按如下方式拆分逗号分隔的字符串: var

我正在尝试让LINQ to SQL正常工作。问题是parsedSeasons是一个类似“1,2,3”的字符串,h.season是一个int列。我怎样才能让它正常工作

  var id = (from h in db.t_ref_harvest_type
                  where parsedSeasons.Contains(h.season)
                  select new { h.id });

您需要先按如下方式拆分逗号分隔的字符串:

var Seasons = parsedSeasons.Split(',').Select(int.Parse);
然后使用LINQ查询:

var id = (from h in db.t_ref_harvest_type
                  where Seasons.Contains(h.season)
                  select new { h.id });

您需要先按如下方式拆分逗号分隔的字符串:

var Seasons = parsedSeasons.Split(',').Select(int.Parse);
然后使用LINQ查询:

var id = (from h in db.t_ref_harvest_type
                  where Seasons.Contains(h.season)
                  select new { h.id });

你可以在链接中得到这个你可以在链接中得到这个我得到以下错误…实例参数:无法从'string[]'转换为'System.Linq.IQueryable'是的,你是对的,我们忘记了将分隔的元素转换为int。我已经编辑了我的答案。如果还有其他错误,请告诉我。我遇到以下错误…实例参数:无法从“string[]”转换为“System.Linq.IQueryable”是的,您是对的,我们忘记了将分隔的元素转换为int。我已经编辑了我的答案。如果还有别的事,请告诉我。