1

Coming from This Example
I have a data context

public class AggregateContext : DbContext
{
    public DbSet<BlogEntry> BlogEntries { get; set; }
    public DbSet<UserProfile> UserProfiles { get; set; }
}

And in app start I have this

        Database.SetInitializer(new TestingDbInitializer());
        new AggregateContext().UserProfiles.Find(1);

And my Initializer looks like this

  public class TestingDbInitializer : DropCreateDatabaseAlways<AggregateContext>
{
    protected override void Seed(AggregateContext context)
    {
        AccountsContext(context);
        // add a bunch of Lorems to the blog. does call context.SaveChanges();
        BlogsContext(context);
    }

    void AccountsContext(AggregateContext context)
    {
        WebSecurity.InitializeDatabaseConnection(
            "DefaultConnection",
            "UserProfile",
            "UserId",
            "UserName",
            autoCreateTables: true);

        //create Admin
        if (!WebSecurity.ConfirmAccount("Admin"))
        {
            var confirm = WebSecurity.CreateUserAndAccount(
                "Admin",
                "password",
                new { Email = "[email protected]" });

            if (!Roles.RoleExists("Admin"))
                Roles.CreateRole("Admin");

            Roles.AddUserToRole("Admin", "Admin");
        }
    }

When I run it I crash on this line.

var confirm = WebSecurity.CreateUserAndAccount( "Admin", "password", new { Email = "[email protected]" });

with the sqlexception "Invalid column name 'Email'."
Looking at my database in server explorer I see that the email column was not created.

1 Answer 1

1
public class AggregateContext : DbContext
{
    public AggregateContext()
        : base("DefaultConnection")
    {
    }
    public DbSet<BlogEntry> BlogEntries { get; set; }

    public DbSet<UserProfile> UserProfiles { get; set; }
}

Forgot to define the connection. Go Me !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.