I have a repository method like,
public List<Township> lst(string multipletownship)
{
var foo = from x in db.Townships
select new { x.TownshipID, x.JTownshipName };
string[] sarr;
if (multipletownship.Contains(','))
{
sarr = multipletownship.Split(',');
foo = foo.Where(s => s.TownshipID == sarr[0] || s.TownshipID==sarr[1]);
}
else
{
foo = foo.Where(s => s.TownshipID == multipletownship);
}
multipletownship parameter value is 1,2.These are township id.The question is how can i filter townshipid to multiple at the if condition.It that possible or I have to do with some loop…
If there is no
,in multipletownship string, then you will get an array with single item: