Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4022464
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:28:42+00:00 2026-05-20T10:28:42+00:00

We have a database that has been deployed to various clients. We are currently

  • 0

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.

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)

Thanks

Edit: 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:

[Boolean(Properties.Settings.Default.TableExists)]
public class NamedController : Controller

Which throws a page not found if false?

Edit 2: With the Suggestions given by people to use the config settings i ended up with the following solution

App settings to set whether the table exists

<appSettings>
    <add key="tableExists" value="True"/>
</appSettings>

a custom data annotation to say whether to allow access to controller

[AuthoriseIfTableExistsIsTrue]
public class NamedController : Controller

the code for the custom authorise

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");
    }
}

Thanks everyone for the help and telling me not to use EF for this and use config setting instead

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:28:43+00:00Added an answer on May 20, 2026 at 10:28 am

    A much better option would be to store the version differences as configuration. This could be stored in the database itself, a configuration file or even web.config.

    Otherwise you’ll end up with messy code like:

    int result = entity.ExecuteStoreQuery<int>(@"
        IF EXISTS (SELECT * FROM sys.tables WHERE name = 'TableName') 
            SELECT 1
        ELSE
            SELECT 0
        ").SingleOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that has been populated with some data using create and
I have a database structure that has two one-to-many relationships. I have a website,
I use database that has been created by someone else and I can't change
We have a database that has a bunch of records with some bad data
I have recently started work on a project that has already been running for
My general question is, say you have a SQL Server 2005 database that's 20G
I have a solution that uses NServicebus which contains at least 3 projects that
We have a database server application which consists of the followings components: 1) A
Basically when I have an application in XCode and I change the sqlite/coredata database
I need to change the database connection string in the web.config file but havent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.