[Solved] How to update database using dictionary with linq


This will let you loop over your dictionary values:

foreach (string key in dictionary.Keys) {
    string value = dictionary[key];
    //Now, do something with value, such as add to database
}

And this will let you find a specific dictionary value:

string key = "a_key";
if (dictionary.ContainsKey(key)) {
    string value = dictionary[key];
    //Now do something with value
}

I think you are looking to do something like the second example above.

What’s confusing about your code example is that you have !dictionary.ContainsKey, which means that the key does not exist in the dictionary, but your comment says //here must be these new key-value from dictionary. This makes me think that maybe you intend for dictionary.ContainsKey rather than !dictionary.ContainsKey and that you then want to retrieve the value and do something with it. But I’m not sure.

In any case, perhaps you are asking simply how to get the value out of the dictionary, and in that case, you may find the dictionary[key] notation using brackets to be useful. Is that what you were going for?

1

solved How to update database using dictionary with linq