我有一个数据上下文
public class AggregateContext : DbContext
{
public DbSet<BlogEntry> BlogEntries { get; set; }
public DbSet<UserProfile> UserProfiles { get; set; }
}在应用程序启动中我有这个
Database.SetInitializer(new TestingDbInitializer());
new AggregateContext().UserProfiles.Find(1);我的初始化器看起来像这样
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 = "please@help.me" });
if (!Roles.RoleExists("Admin"))
Roles.CreateRole("Admin");
Roles.AddUserToRole("Admin", "Admin");
}
}当我运行它时,我会在这条线上崩溃。
变量确认= WebSecurity.CreateUserAndAccount(“管理”,“密码”,新的{ Email = "please@help.me“});
使用sqlexception“无效列名‘电子邮件’”。
在服务器资源管理器中查看我的数据库,我发现并没有创建电子邮件列。
发布于 2012-12-21 02:08:51
public class AggregateContext : DbContext
{
public AggregateContext()
: base("DefaultConnection")
{
}
public DbSet<BlogEntry> BlogEntries { get; set; }
public DbSet<UserProfile> UserProfiles { get; set; }
}忘了定义连接。跟我走!
https://stackoverflow.com/questions/13983318
复制相似问题