Visual Studio MVC 4 web app, SQL Server 2008 R2, Entity Framework 5
Visual Studio MVC 4 Web应用程序,SQL Server 2008 R2,实体框架5
I have automatic migrations enabled (in configuration.cs):
我启用了自动迁移(在configuration.cs中):
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = false;
}
As a precaution, DataLossAllowed is disabled. What's the best way to run this migration manually, locally and on the server?
作为预防措施,DataLossAllowed已禁用。手动,本地和服务器上运行此迁移的最佳方法是什么?
I get this error:
我收到此错误:
The "WebSecurity.InitializeDatabaseConnection" method can be called only once.
when I try to run it from package-manager.
当我尝试从包管理器运行它时。
It seems like manually running migrations, and making them automatic are incompatible?!
看起来像手动运行迁移,并使它们自动化是不兼容的?!
1
That error looks like you are initializing your database connection more than once rather than having an issue with Migrations.
该错误看起来像是多次初始化数据库连接而不是迁移问题。
WebSecurity.InitializeDatabaseConnection
is what is called when you use the [InitializeSimpleMembership]
attribute, which in MVC4 decorates the Accounts controller by default.
WebSecurity.InitializeDatabaseConnection是使用[InitializeSimpleMembership]属性时调用的属性,默认情况下,MVC4在属性中装饰Accounts控制器。
As you only want this to be called once, you should remove the attribute from your Account Controller and add a call to WebSecurity.InitializeDatabaseConnection
to AuthConfig file, which is called on application start by global.asax. You could put it straight into the application start method in global.asax or make your own file but AuthConfig seems the best place for it in my opinion.
由于您只希望调用一次,因此应从Account Controller中删除该属性,并将对WebSecurity.InitializeDatabaseConnection的调用添加到AuthConfig文件,该文件在应用程序启动时由global.asax调用。您可以直接将其放入global.asax中的应用程序启动方法或创建自己的文件,但AuthConfig似乎是我认为最好的地方。
The code for it looks like this
它的代码看起来像这样
WebSecurity.InitializeDatabaseConnection("DatabaseConnectionString","UserProfile","UserId","UserName", false);
renaming the DatabaseConnectionString
to the name of your connection string in web.config Also the false may be True if you are not using Db First.
将DatabaseConnectionString重命名为web.config中连接字符串的名称如果您不使用Db First,则false也可能为True。
Once you do that, you can remove the InitializeSimpleMembership file from the filters folder too.
完成后,您也可以从filters文件夹中删除InitializeSimpleMembership文件。
This will ensure that InitializeSimpleMembership
is only called once.
这将确保只调用一次InitializeSimpleMembership。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2013/06/02/fcc175b74b11611a52792ba4cee23a59.html。