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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:48:02+00:00 2026-06-02T05:48:02+00:00

I am trying to seed some data using custom database initializers, but can’t get

  • 0

I am trying to seed some data using custom database initializers, but can’t get it to work. I tried adding some configurations to appConfig file but that didn’t work either.

It is a WPF application and I don’t want to reference my EntityLibrary. I want to seed data using context’s constructor. What’s wrong with it?

Edit: The problem is no data gets populated. When debugging I see the context’s constructor SetInitiazlier function is called but overridden Seed method never gets called, in fact debugger never enters the Seed method.

At the same time XAML parser gives an error complaining about the TContext type paramter of
DropCreateDatabaseIfModelChanges. I can’t give the exact error since I don’t have the code at home.

This is my custom initializer:

public class DbInitializer : DropCreateDatabaseIfModelChanges<DemirbaşContext>
    {
        protected override void Seed(DemirbaşContext context)
        {
            Kullanıcı kullanıcı = new Kullanıcı
            {
                Ad = "Mert",
                Soyad = "Mert",
                KullanıcıAdı = "admin",
                Şifre = "password",
                Email = "mert@mert.com"
            };

            context.Kullanıcılar.Add(kullanıcı);
            context.SaveChanges();

            base.Seed(context);
        }
    }

This is my context constructor:

public DemirbaşContext():base("Demirbaş")
    {
        Database.SetInitializer<DemirbaşContext>(new DbInitializer());
    }

EDIT 1: Here is my current code, but still it does not seed the data. Can you see what’s wrong?

Initializer:

public class DbInitializer : DropCreateDatabaseIfModelChanges<DemirbaşContext>
{
    protected override void Seed(DemirbaşContext context)
    {
        Kullanıcı kullanıcı = new Kullanıcı
        {
            Ad = "Mert",
            Soyad = "Mert",
            KullanıcıAdı = "admin",
            Şifre = "password",
            Email = "mert@mert.com"
        };

        context.Kullanıcılar.Add(kullanıcı);
        context.SaveChanges();

    }
}

Application Startup:

public partial class App : Application
    {
        public App()
        {
            // Seed data, remove after getting seeding in custom db initiazlier to work
            DemirbaşContext context = new DemirbaşContext();
            DbInitializer initializer = new DbInitializer();
            Database.SetInitializer<DemirbaşContext>(initializer);
            context.Database.Initialize(false);
        }
    }
  • 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-06-02T05:48:05+00:00Added an answer on June 2, 2026 at 5:48 am

    Move your initialization code to your application startup. It doesn’t belong to context’s constructor and force initialization manually:

    Database.SetInitializer<DemirbaşContext>(new DbInitializer());
    context.Database.Initialize(false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to insert some sample data (Seed data) using EF 4.3 Migration. The
I'm trying to seed some data into a Rails 3 app that I'm developing,
I'm trying to parse a XML using Apache Commons JXPath. But for some reason,
I'm trying to seed a database in Rails 3 with images using CarrierWave, however
I'm trying to seed my database with the standard db/seeds.rb method. This works fine
I'm trying to seed a blank database from the production db via the Import/Export
When I'm trying to seed my database, I started getting this error: rake aborted!
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
I have a lot of data that I'm trying to seed into a polymorphic
I am trying to build an array of custom object references. Here is some

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.