title: Check if a table exists within a database using LINQ
body: <p>We have a database that has been deployed to various clients. We are currently introducing a optional new feature that, to be used, will require the customers who want the feature to have a new table added to the existing database. </p>
  
  <p>As we are rolling out a new piece of software that will have to interact with versions of the database both with and without the new table (and as we don't want 2 versions one for customers who have the new table and one for ones who don't) we were wondering if it is possible to programmatically determine (with entity framework) whether a table exists in the database (I can try to access the table and have it throw a exception but was wondering if there was a built in function to do this)</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit:</strong> Given that people are telling me i should be using a config file not checking with EF can anyone give me guidence on how to check the config file with, for example, a custom data annotations for a mvc controller. Something like:</p>
  
  <pre><code>[Boolean(Properties.Settings.Default.TableExists)]
  public class NamedController : Controller
  </code></pre>
  
  <p>Which throws a page not found if false?</p>
  
  <p><strong>Edit 2:</strong> With the Suggestions given by people to use the config settings i ended up with the following solution</p>
  
  <p>App settings to set whether the table exists</p>
  
  <pre><code>&lt;appSettings&gt;
      &lt;add key="tableExists" value="True"/&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>a custom data annotation to say whether to allow access to controller</p>
  
  <pre><code>[AuthoriseIfTableExistsIsTrue]
  public class NamedController : Controller
  </code></pre>
  
  <p>the code for the custom authorise</p>
  
  <pre><code>public class AuthoriseIfTableExistsIsTrue : AuthorizeAttribute
  {
      private readonly bool _tableExists;
  
      public AuthoriseIfTableExistsIsTrue()
      {
          _tableExists = string.Equals(bool.TrueString, ConfigurationManager.AppSettings["tableExists"], StringComparison.InvariantCultureIgnoreCase);
      }
  
      public AuthoriseIfTableExistsIsTrue(bool authorise)
      {
          _tableExists = authorise;
      }
  
      protected override bool AuthorizeCore(HttpContextBase httpContext)
      {
          if (_tableExists)
              return base.AuthorizeCore(httpContext);
          else
              throw new HttpException(404, "HTTP/1.1 404 Not Found");
      }
  }
  </code></pre>
  
  <p>Thanks everyone for the help and telling me not to use EF for this and use config setting instead</p>