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 7007549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:37:18+00:00 2026-05-27T21:37:18+00:00

I successfully created my first Entity Framework Code first project using SQL Server CE.

  • 0

I successfully created my first Entity Framework Code first project using SQL Server CE. The database tables were created automatically and all was well.

I then changed my connection string to point to a SQL Server database I’d created and expected it to autogenerate the tables. It didn’t and instead complained about the tables not existing.

After some reading I found that I needed to add an initializer to my App_Start method.

I tried:

// Method 1
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<EFContext>());

But this didn’t work at first because it couldn’t find an EdmMetaData table to discover if the model had changed.

So I tried adding:

// Method 2
Database.SetInitializer(new CreateDatabaseIfNotExists<EFContext>());

But this didn’t work because I’d already created the database, and when I removed the database it still didn’t work because the user I was logging in as didn’t have create database privileges.

I finally tried:

// Method 3
Database.SetInitializer(new DropCreateDatabaseAlways<EFContext>());

Which worked, but I don’t really want to drop the db every time. So once it ran and added the EdmMetaData table I replaced it with method 1 and that now works fine.

Although this method works, it doesn’t feel as elegant as when I was using SQL Server CE and I’ve not found someone suggesting that you use this method.

So, am I missing something and is there an easier, more elegant way to do this?

  • 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-27T21:37:18+00:00Added an answer on May 27, 2026 at 9:37 pm

    Method 1 and 2 expects that database doesn’t exist yet. They don’t work if you create database manually. If you need EF to create tables in existing database you must create custom database initializer.

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

Sidebar

Related Questions

I am successfully creating database (SQL Ce) using Entity Framework Code First approach (C#-WPF).
I have successfully created a database and performed my first migration using: class CreateUsers
I'm trying out the new scaffolding features in MVC 3, using Entity Framework Code
I'm learning ASP.NET MVC 3 with Entity Framework Code First. I'm following a tutorial
I am using WCF for the first time. I Have successfully created the service
I have successfully created my first django project. I have two apps in my
I created a google app engine project. I just successfully mapped it to a
I succesfully created a project using seam credentials for authentication, but right now some
I created my first Silverlight application. In the client project, I want to define
I created a setup project to install my application (*.bat file) and successfully installed

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.