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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:51:52+00:00 2026-05-23T02:51:52+00:00

Using EF 4.1 Code first I wanted to stop EF creating database from Models.

  • 0

Using EF 4.1 Code first I wanted to stop EF creating database from Models. As I understand if you pass Connectionstring name it will use existing database from that connection string. However if the database does not exists then it will create database will all the tables form the model.

  <connectionStrings>
<add name="DiaryContext" connectionString="Data Source=.;Initial Catalog=Diary;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>

        public MyDiaryContext() : 
        base("name=DiaryContext")
    {
        this.Configuration.LazyLoadingEnabled = true;
        this.Configuration.ProxyCreationEnabled = false;
    }

In the above example its behaving as follows:

(1) if database does not exists then it will create the database with all the tables etc.

(2) if the database exists and it has no tables then it will not create new tables

(3) if I add new model the EF code then it will not create the new table in the database.

I am happy with 2 and 3 but in case of (1) if database does not exists then I wanted it to throw the exception instead of creating the db and tables.

In my case the database is being managed by DBA and I dont have total control over this.

Does anyone have any idea how to achive this?

Many thanks,

  • 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-23T02:51:53+00:00Added an answer on May 23, 2026 at 2:51 am

    When you use EF Code first you need to set a DB Initializer I for example do this in the constructor of my DataContext

    Database.SetInitializer(new DropCreateDatabaseIfModelChanges<WebContext>());
    

    There are a few default implmentations like DropCreateDatabaseIfModelChanges and DropCreateDatabaseAlways you can use. If however you don’t wont any DB or tables generate just make sure that no Initializer is being set or inherited from and you can use the model against an existing db. Good article by scot gu

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

Sidebar

Related Questions

I am using the Code-First approach with EF and I wanted to use IDbSet
A bit of background first: I am using base code from a remote SVN
After checking out code for the first time from a repository into Eclipse using
I have an AXIS2/JAX-WS web service using a code first implementation (yes I know,
I'm using the STL map data structure, and at the moment my code first
I have been using this code with great success to pull out the first
I am trying to parallelise a code using scala actors. That is my first
I am using the following code to get an alphabetic number of a first
Let me first put the code snippets here. I am just using the ASP.NET
How to get the first child id inside the div using JQuery. Sample code:

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.