就像标题所说,我正在使用Entity Framework 6.当我调用Update-Database时,种子方法失败:
SimpleMembershipProvider userMgr = new SimpleMembershipProvider();
if (WebSecurity.Initialized)
{
if (userMgr.GetUser("administrator", false) == null) //--> Throws the exception
{
userMgr.CreateUserAndAccount("administrator", "password", false, null)
...
}
}
抛出的异常:
System.InvalidOperationException: You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site.
at WebMatrix.WebData.SimpleMembershipProvider.get_PreviousProvider()
at WebMatrix.WebData.SimpleMembershipProvider.GetUser(String username, Boolean userIsOnline)
at SomeProject.Migrations.Configuration.Seed(SomeProjectDB context) in c:\Users\Me\Documents\Visual Studio 2013\Projects\SomeProject\SomeProject 2.0\Migrations\Configuration.cs:line 73
...