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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:44:18+00:00 2026-05-30T11:44:18+00:00

Previously I used a database initializer to seed or pre-populate my tables when creating

  • 0

Previously I used a database initializer to seed or pre-populate my tables when creating them using Code First. This all worked great but I wanted to move on to using the EF 4.3 migrations.

I updated to EF 4.3 in my project and removed the database initializer code and put it within the Seed method on the migrations Configuration.cs file. This is all working ok for me for prepopulating my tables except for when I want to seed a default user into my user table.

I use the following code within my Seed method: (currently this doesn’t use the AddOrUpdate code as I’m not sure how to use that for this situation – hence the username check)

        // create default User
        MembershipCreateStatus status = new MembershipCreateStatus();
        User admin = context.Users.Find("TestGuy");
        if (admin == null)
        {
            Membership.CreateUser("TestGuy", "TestGuy123", "testguy@test.com");
            if (status == MembershipCreateStatus.Success)
            {
                admin.Firstname = "Test";
                admin.Surname = "Guy";
                admin.DateLastActivity = DateTime.Now;
                admin.LastActivityRoute = "/Home/Index";
                Role adminRole = context.Roles.Find("Administrator");
                admin.Roles = new List<Role>();
                admin.Roles.Add(adminRole);
            }
        }

When I try and run Update-Database I get this error:

The password-answer supplied is invalid.

I think this is just down to how I call the CreateUser but I can’t seem to work out how to get around this bug. I’ve tried putting in just nulls for the security question and answer but that doesn’t seem to work.

Has anyone an example of seeding a user using the ‘AddOrUpdate’ option?

EDIT 1:

As per one of the comments below, I am using Altairis Security Toolkit to manage my membership. My web.config is setup as follows:

<membership defaultProvider="TableMembershipProvider">
  <providers>
    <clear />
    <add name="TableMembershipProvider" type="Altairis.Web.Security.TableMembershipProvider, Altairis.Web.Security" connectionStringName="DataContext" minRequiredPasswordLength="8" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" minRequiredNonAlphanumericCharacters="0" passwordStrengthRegularExpression="" />
  </providers>
</membership>

EDIT 2:

I have also put this as an open ticket on the Altairis forum.
http://altairiswebsecurity.codeplex.com/workitem/32273

EDIT 3:

To get this working without any error I had to setup my code as follows:

        // create default User
        MembershipCreateStatus status = new MembershipCreateStatus();
        User admin = context.Users.Find("TestGuy");
        if (admin == null)
        {
            Membership.CreateUser("TestGuy", "TestGuy123", "testguy@test.com", null, null, true, out status);
            if (status == MembershipCreateStatus.Success)
            {
                admin = context.Users.Find("TestGuy");
                admin.Firstname = "Test";
                admin.Surname = "Guy";
                admin.DateLastActivity = DateTime.Now;
                admin.LastActivityRoute = "/Home/Index";
                Role adminRole = context.Roles.Find("Administrator");
                admin.Roles = new List<Role>();
                admin.Roles.Add(adminRole);
            }
        }

The above will compile now when running Update-Database but no new user is generated. If anyone has suggestions to try that would be great!

Thanks,

Rich

  • 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-30T11:44:20+00:00Added an answer on May 30, 2026 at 11:44 am

    From doing some research on this issue it’s become apparent that the user seeding should be created outside the migrations seed logic – at least for now until they make it easier to do!

    As a work around I followed the example from this Stackoverflow question (Best way to incrementally seed data in Entity Framework 4.3) to manually make my new user on start up outside of the migrations configuration file.

    It’s not ideal, at least to me, as all ‘startup’ data is not in one area but it gets the job done and isn’t that difficult to follow.

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

Sidebar

Related Questions

How get data from mysql database? I use ASP.NET and C#.Previously, I used LINQ
I have a webapp written in PHP using a MySQL database backend. This question
Greetings I may have imagined this but does anyone know if Last.fm previously used
I build database-driven web sites. Previously I have used Perl or PHP with MySQL.
Previously we used DB2 as database, but now we are migrating to Oracle. Now,
I'm currently using php to populate a form with selections from a database. The
I'm a java developer who used Netbeans 6.8 previously and running all of the
I've previously used jquery-ui tabs extension to load page fragments via ajax , and
I'm looking into development standards fro JavaScript. I had previously used Doulgas Crockfords Javascript
The only type of 'remote desktop' application I've used previously is VNC viewer. My

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.