0

I am using LINQ
I have a Configuration table to store key values it has 30 settings in 30 rows For eg:

 setting       value
    A            2
    B           "xyz" 
    .
    .
    .
    .
    .
 and so on 

I have created Property class to hold all values from database.

I want to hold these settings in property class

so in which way i can fetch and set all these properties.

Do i have to loop through all rows and set properties one by one

or what are your efficient suggestions

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
donstack
  • 2,557
  • 3
  • 29
  • 44

1 Answers1

4

Read the table and load it into a Dictionary. Use the setting as Key and the Value as value.

Dictionary<string, string> dictionary = new Dictionary<string, int>();
dictionary.Add("A", "2");
dictionary.Add("B", "xyz");

Then when you need a setting you can just perform

var settingA = Int.Parse(dictionary["A"]);
var settingB = dictionary["B"]

So now you can do:

Objectset.SettingEntities.ForEach(x => dictionary.Add(x.setting, x.value));

This is less overhead then loading every field into it's own property, because then you will have to assign each value manually and do the required checking.

JMan
  • 2,611
  • 3
  • 30
  • 51