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

  • SEARCH
  • Home
  • 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 7524555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:06:34+00:00 2026-05-30T03:06:34+00:00

I am attempting to deploy my app to a testing environment, but cannot get

  • 0

I am attempting to deploy my app to a testing environment, but cannot get Entity Framework to play nicely with the database. In development, I use a database initializer to seed the database and that has worked flawlessly. However, when I deploy the application to an actual IIS instance I cannot get it to interface with the database. My custom initialization rules aren’t run at all, so I am instead creating the database manually.

I used the ObjectContext.CreateDatabaseScript() as a starting point for my SQL script, and SSMS verifies that two rows are populated in the appropriate table.

My problem arises after running the application. I have custom membership and role providers, neither of which seem to detect that the two roles exist in the database.

How do I get my entity framework to recognize that these rows aren’t empty? I’m currently using a private DbContext inside a repository to handle communication with Entity Framework, and disabled my custom initializer until this hiccup is resolved.

Code that attempts to find roles in the database:

context.Roles.Single(r => r.Name == role)

The database shows the following in the Roles table:

Id  Name     Description
1   Company  NULL
2   Customer NULL

The LINQ generates an empty sequence exception, as context.Roles is empty.

  • 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-30T03:06:35+00:00Added an answer on May 30, 2026 at 3:06 am

    Here are the steps I went through to migrate from a code first project with a custom IDatabaseInitializer implementation that reset the database during each session to a non-volatile DB setup.

    First, copy the schema generated by Entity Framework in your dev. project by running the following code and placing the output in an accessible location (ie: file on desktop, raw text in browser, etc). context is an instance of your class that inherits from DbContext:

    ((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript()
    

    Second, save the string returned from that call in a SQL file. Be sure to remove the command that creates the Entity Framework meta data table. This command should resemble the following:

    create table [dbo].[EdmMetadata] 
    ( 
        [Id] [int] not null identity, 
        [ModelHash] [nvarchar](max) null, 
        primary key ([Id]) 
    );
    

    Next, remove the code that seeds the database. I used an AppSetting so that I can easily toggle that code’s usage after deployment without needing to re-compile and deploy.

    if (ConfigurationManager.AppSettings["Mode"] == "Dev")
    {
        Database.SetInitializer<PonosContext>(new PonosInitializer());
        new MyContext().Database.Initialize(true);
    }
    

    Immediately outside of that statement, you still need to intialize the database, but make sure to pass in false so that the initializing will only happen if the database has not been initialized.

    new MyContext().Database.Initialize(false);
    

    Finally, run your setup SQL on an empty database to have the tables created with appropriate fields.

    If you deploy and then run your application, it should connect to the database and be able to work as normal with any data you loaded in an external script. I tested this method successfully with custom membership and role providers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to deploy a WinForms app in a Citrix environment. It's been working
I'm hit a problem when attempting to deploy a MVC app as a sub-application
I am attempting to deploy my first app on Heroku and having a little
I am attempting to deploy a RoR app using Passenger onto my DreamHost hosting
I am developing a Ruby on Rails app and attempting to deploy it with
I have a Django app we're attempting to deploy to a Tomcat server, using
We use teamcity to deploy several of our projects. I'm attempting to setup the
I'm attempting to use the VS2010 command line utility, devenv.exe, to deploy a web
I'm attempting to deploy my symfony2 app to my ec2 instance. I have my
I built an app using Django 1.3 and am now attempting to deploy to

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.