0

我的 Migrations/Configuration.cs 中有一个 Seed 方法:

  protected override void Seed(MVC4App.Models.MVC4Entities context)
  {
     try
     {
        // Initialize database for Account
        WebSecurity.InitializeDatabaseConnection(
           "MVC4Entities", "Users", "UserId", "Email", autoCreateTables: true);

如果我尝试在我的开发机器上运行“update-database -verbose”,我会收到以下错误:

The "WebSecurity.InitializeDatabaseConnection" method can be called only once.

这是我的代码中唯一调用它的地方。我怎样才能解决这个问题?

谢谢

4

1 回答 1

2

添加初始化检查:

if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection(
           "MVC4Entities", "Users", "UserId", "Email", autoCreateTables: true);
}
于 2013-06-10T21:20:09.197 回答