I have an object with a string-typed parameter called ‘baan_cat_fam_code‘. The code below is my attempt to find all items in the query that have a baan_cat_fam_code that exist in a generic string list called catFamCd.
query = query.Where(r => r.baan_cat_family_code.Any(s => catFamCode.Contains(s)));
The problem is that this won’t compile – I get an error that states
"Argument type 'char' is not assignable to parameter type 'string'"
for some reason the predicate s is typed as char. So I append .ToString() to the argument in the .Contains method. However, when the code runs, I get the following exception thrown when the result of the query is bound to a listbox.
"The argument 'value' was the wrong type. Expected 'System.Char'. Actual 'System.String'."
This has got me scratching my head. Any assistance would be greatly appreciated.
Thanks!
The problem you’re running into is that
baan_cat_family_codeis of typestringwhich implementsIEnumerable<char>. When you callAnyit’s essentially sayingcharin thisstringWhat you really want to be asking though is
stringin the listcatFamCodeTry the following which does the latter