Reading database table into a .NET object of different structure -
i have inflation rates stored in database following structure:
when reading above data, need initialize business objects different structure dynamically , fill them database data.
if database above, need create 2 objects: "uk inflation forecast" , "germany inflation forecast". in case, both objects have 6 properties: countryname (as string) , 5 inflation values (as double).
how can create object classes without knowing number of properties needed , how fill these data?
i create class of following structur:
public class inflationclass { public inflationclass() { inflationvalues = new dictionary<int, double>(); } public string country { get; set; } public dictionary<int, double> inflationvalues { get; private set; } }
and load data so
int sampleyear = 2016; double samplevalue = 123456789.01; var inflation = new inflationclass(); if(!inflation.inflationvalues.containskey(sampleyear )) { inflation.inflationvalues.add(sampleyear , samplevalue); }
i've used c# can converted vb.net if prefer.
Comments
Post a Comment