Thursday, October 09, 2008

Linq: Split string array and convert into integer using a converter / lambda and then selecting where in or contains from that list

// This will split an CSV string array into an array of integers
int[] intArr = Array.ConvertAll( priorityCsv.Split(','), n => Convert.ToInt32(n) );

//This will select the count of values where there are in or contain the values in the array
return (from v in this.Context.VACompanyErrors where intArr.Contains(v.Priority) select v).Count();