我的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.
这是我的代码中唯一被调用的地方。我该如何解决这个问题?
由于
答案 0 :(得分:2)
添加初始化检查:
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection(
"MVC4Entities", "Users", "UserId", "Email", autoCreateTables: true);
}