0
如何从不同的数据表调用中读取特定类型成员的字典?加载特定类型的字典值
- 我使用的方法HashSet.ToDictionary
- 然后我打电话给DB和要加载的对象(属性值1)
- 最后,我将调用另一个数据库,发现和预填入填充字典现有对象的Value2属性
HashSet <string> hashset = new HashSet <string>();
Dictionary < string, CustomeObject > dictionary = new Dictionary < string, CustomeObject >();
dictionary = hashset.ToDictionary(h => h, h => (CustomeObject) null);
while (firstreader.Read()) {
if (dictionary.ContainsKey(firstreader.GetValue(1).ToString())) {
dictionary[firstreader.GetValue(1).ToString()] = new CustomeObject() {
Key = firstreader.GetValue(1).ToString(),
Value1 = firstreader.GetValue(2).ToString(),
Value2 = null
};
}
}
while (secondreader.Read()) {
if (dictionary.ContainsKey(secondreader.GetValue(1).ToString())) {
dictionary[secondreader.GetValue(1).ToString()] = new CustomeObject() {
Key = "", //Persist the value from previous load
Value1 = secondreader.GetValue(2).ToString(),
Value2 = null;
};
}
}