I get a dictionary and i want to get the matching database entries for the key field in the dictionary.
So the code below gets all database fields that equals the data in the dictionary.keys. So far so good. Now when i loop it and i try to get the field from the fields that matches the key x it fails with an exception:
{“Comparison operators not supported for type ‘System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.String]'”}
var fields = _dc.fieldInfos.Where(x => x.name.Equals(param.MethodData.Keys));
foreach (var entry in param.MethodData)
{
KeyValuePair<string, string> entry1 = entry;
var field = fields.SingleOrDefault(x => x.name.Equals(entry1.Key));
if (field == null)
....
}
The line that fails is this:
var field = fields.SingleOrDefault(x => x.name.Equals(entry1.Key));
Any ideas?
Be mindful that the
_dc.fieldInfos.Where(x => x.name.Equals(param.MethodData.Keys))(line 1) doesn’t actually get executed until you try to iterate overfields(line 5).At that point,
x.name.Equals(param.MethodData.Keys)fails because astring(x.name) cannot be compared toKeyCollection<string>(param.MethodData.Keys).Essentially, you are getting the exception on unexpected line because of the deferred execution.