title: loading configuration settings from a database
body: <p>I'm currently writing a MVVMC application in C# (utilising Entity Framework).</p>
  
  <p>What is the correct (best practice) way for loading and storing configuration values?</p>
  
  <p>First of all, there is the question of how to store the configuration settings... would the best way to have the table designed like this: tblConfig(configid, configref, configval) or like this:  tblConfig(configid,option1,option2,option3)  - replacing option1 etc, with meaningful names (e.g. logoimage)</p>
  
  <p>Next, there is how to retreive/store the settings in the app; My idea was to store the configuration in a table in the database, and then create a static class - something like this:</p>
  
  <pre><code>public static class ConfigClass
  {
  
      public static ConfigClass()
      {
          //load values from database
          ContextClass SiteContext = new ContextClass();
  
          logoImage = SiteContext.ConfigSettings.ToList().Find(c =&gt; c.configreference == "logoimage").configvalue;
          admintoauthoriseaccounts = Convert.ToBoolean(SiteContext.ConfigSettings.ToList().Find(c =&gt; c.configreference == "logoimage").configvalue);
          defaultaccountrole = Convert.ToInt32(SiteContext.ConfigSettings.ToList().Find(c =&gt; c.configreference == "logoimage").configvalue);
  
      }
  
      public static string logoImage = "";
      public static bool admintoauthoriseaccounts = true;
      public static Int32 defaultaccountrole = 1;
  
  }
  </code></pre>
  
  <p>Class for the ConfigSetting DbSet Repository:</p>
  
  <pre><code>public class ConfigSetting
  {
      public string configreference { get; set; }
      public string configvalue { get; set; }
  }
  </code></pre>
  
  <p>Is this a good idea? Or should I forget the static class and just read settings directly out of the the DbSet repository?</p>
  
  <p>Thanks.</p>