KeelRisk
KeelRisk

Reputation: 749

LINQ to SQL with 'Contains' and an INT column. How do you make it work?

I'm trying to get this LINQ to SQL to work. The problem is parsedSeasons is a string like "1,2,3" and h.season is an int column. How can I get this to work correctly?

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

Upvotes: 1

Views: 2321

Answers (1)

msigman
msigman

Reputation: 4524

You need to first split your comma delimited string like this:

var Seasons = parsedSeasons.Split(',').Select(int.Parse);

Then use your LINQ query:

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

Upvotes: 1

Related Questions