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_code
is of type string
which implements IEnumerable<char>
. When you call Any
it's essentially saying
char
in this string
What you really want to be asking though is
string
in the list catFamCode
Try the following which does the latter
query = query.Where(r => catFamCode.Contains(r.baan_cat_family_code));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With