Reputation: 7490
I have a linq database function which worked fine, however changes had to be made to the types holding certain bits of infomation outside of my control.
The currect situation is I have an asp.net 3.5 site, with infomation stored in a dictionary.
the code I have was
Table.Insert(_rules.RuleList
.Where(rule => !ruleRecords
.Any(r => r.RuleID == rule.RuleID)
));
As you can see it excludes where r.RuleID == rule.RuleID
All good, however 'r' is no longer an object, and is now a dictionary.
Any Ideas how I can get the value of the dictionary, by providing the key ("RuleID") inside the linq query?
Any suggestions greatly appreciated, however I can not update to 4.0 and I cant have the data not stored in an object, unless it can be a temporary conversion
Upvotes: 0
Views: 239
Reputation: 1309
What your asked for (how to get the value in a dict, providing a key): dict[key]
, so in your case r[rule.RuleID]
As was pointed out in another answer what you probably want is: Dictionary.ContainsKey
Upvotes: 1
Reputation: 11915
As long as the key of your dictionary is RuleId
, I think you can re-write this as:
Table.Insert(_rules.RuleList.Where(rule => !ruleRecords.ContainsKey(rule.RuleId))
Upvotes: 0