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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:08:51+00:00 2026-05-28T06:08:51+00:00

I am trying to seed a database with the code first ability of EF

  • 0

I am trying to seed a database with the code first ability of EF 4.1

I have the following code in my Application_Start method of Global.asax

Database.SetInitializer<Context>(new DataContextInitializer());

My Context class contains just a few Public DbSet statements.

Here is my DataContextIntilializer class:

public class DataContextInitializer: CreateDatabaseIfNotExists<Context>
{
    protected override void Seed(Context context)
    {

        new List<Member>{
        new Member { LastName = "Allen", FirstName = "Steve", Email = "Jeremy_Allen@Domain.com" },
        new Member { LastName = "Mickey", FirstName = "Mouse", Email = "mickey_mouse@Domain.com" },
        new Member { LastName = "Optimus", FirstName = "Prime", Email = "Optimus_Prime@Domain.com" },

   }.ForEach(m => context.Members.Add(m));

   base.Seed(context);
}

My “protected override void Seed” method is not even being called. Is my implementation incorrect? Am I missing something?

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-28T06:08:52+00:00Added an answer on May 28, 2026 at 6:08 am

    Is your database created? How did you trigger database creation? Setting initializer will only tell EF what initializer it should use once database is needed but it doesn’t trigger the creation. The database is created once EF first needs it or once you call for example:

    context.Database.Initialize(false);
    

    Also your initializer will do nothing if your database already exists. It works only in scenario when database doesn’t exist on database server / file system.

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

Sidebar

Related Questions

I am trying to access the Cache in the Application_Start method of Global.asax. I
I'm trying to seed my database with the standard db/seeds.rb method. This works fine
I'm trying to get Entity Framework Code First to create a database for me
I'm trying to use the Entity Framework code first without an existing database. I
I have a lot of data that I'm trying to seed into a polymorphic
I have an XML file containing seed data that I'm trying to load into
I have a small string and a fixed seed and I am trying to
Basically, what I'm trying to do is to seed my database with a bunch
I'm trying to implement the repository pattern using entity framework code first rc 1.
I just started trying my hands on EF4 code first this morning and I

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.