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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:36:07+00:00 2026-05-25T20:36:07+00:00

I have had to suddenly switch to working on Code First Entity Framework 4.1.

  • 0

I have had to suddenly switch to working on Code First Entity Framework 4.1. I started off not knowing anything about this framework but in the last 8 hrs I am now much more comfortable having read blogs and articles.

This blog in particular is one of the best blogs I have seen so far on the topic but the steps given do not match with my experience. In particular, I need more focus on the 3rd and 4th steps (‘Create the Model’ and ‘Swap to DbContext Code Generation’, respectively). I am unable to generate the database from my defined EntitySet. I am getting the SQL and I can execute but I’m getting the following error:

Could not locate entry in sysdatabases for "MyBD" database . No entry found with that name. Make sure that the name is entered correctly entity framework.

If I execute the SQL again, I get the same error following the names of tables that already exist in database.

If refresh the DataConnection in Server Explorer, there are no such tables created as I defined in Entity Framework.

How can I get rid of this error and successfully generate the tables in my .edmx?

Also I am unable to find the option on right-click in Solution Explorer to “Generate Database” from selected class file that has the context class inherited from the DBContext object. I installed the Entity framework 4.1 from Microsoft, so it should appear there… How can I get the Generate Database option?

  • 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-25T20:36:08+00:00Added an answer on May 25, 2026 at 8:36 pm

    If you are creating the database from the model, you need to select the empty model first. Here are the other steps to create db:

    1. Select new connection
    2. Set Server name: if you installed it, just type . to select default. You can also try (local)
    3. Set new database name
    4. Copy DDL script to your SQL server management studio’s query screen
    5. Run the script to create your db

    After running the script, you will have the initial table. Config file will have connection string named as container name.

    Now, when you want to switch to code generation similar to example with TT files, you can right click and add code generation. It will create partial class for the entity model and one file for dbcontext. Similar to this:

     using System;
        using System.Collections.Generic;
    
        public partial class Contact
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }
    

    Context will have only one table.

     public partial class PersonModelContainer : DbContext
        {
            public PersonModelContainer()
                : base("name=PersonModelContainer")
            {
            }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                throw new UnintentionalCodeFirstException();
            }
    
            public DbSet<Contact> Contacts { get; set; }
        }
    

    You dont need TT model. You can add these files directly. You need one context class inheriting from DbContext and one partial class file for each type of entity. If you make a change to model, EF will detect that. You need to define Db initializer. For the sample demo on that webpage, you can add initializer to another method. If it is a web project, you add this init function to Global.asax->application_Start for the initial development. You have different options for initializers. I use drop and create for initial development.

     static void InitDbCheck()
            {
                Database.SetInitializer(new DropCreateDatabaseIfModelChanges<PersonModelContainer>());
                using (var db = new PersonModelContainer())
                {
                    //accessing a record will trigger to check db.
                    int recordCount = db.Contacts.Count();
                }
            }
    
            static void Main(string[] args)
            {
    
    
    
                using (var db = new PersonModelContainer())
                {
                    // Save some data
                    db.Contacts.Add(new Contact { Name = "Bob" });
                    db.Contacts.Add(new Contact { Name = "Ted" });
                    db.Contacts.Add(new Contact { Name = "Jane" });
                    db.SaveChanges();
    
                    // Use LINQ to access data
                    var people = from p in db.Contacts
                                 orderby p.Name
                                 select p;
    
                    Console.WriteLine("All People:");
                    foreach (var person in people)
                    {
                        Console.WriteLine("- {0}", person.Name);
                    }
    
                    // Change someones name
                    db.Contacts.First().Name = "Janet";
                    db.SaveChanges();
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have had a working UIImage picker controller and suddenly it now only
Have had to write my first proper multithreaded coded recently, and realised just how
We have had issues with Mootools not being very backward compatible specifically in the
I had installed Java in my PC and it was working perfectly. Suddenly something
Eclipse can’t see my Android Device on Window.Previously I had been working fine.Suddenly I
We have had SharePoint where I work for a little while now, but we've
I have had to do this several times, usually when trying to find in
I have had a bug recently that only manifested itself when the library was
I have had a few problems with log files growing too big on my
We have/had a phantom delay in our app. This was traced to the initialisation

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.