有没有一种方法,使EF 5 code第一次移民在ASP.NET MVC 4使用SQL Server数据库的一切? [英] Is there a way to make EF 5 code first migrations use a sql server database in ASP.NET MVC 4 for everything?

本文介绍了有没有一种方法,使EF 5 code第一次移民在ASP.NET MVC 4使用SQL Server数据库的一切?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想它在默认情况下的一切使用SQL Server时,我开始新的ASP.NET MVC 4 Web应用程序项目。默认情况下,当你运行这个项目它创建一个的LocalDB实例,并在它创建下表:

I would like for it to use SQL Server by default for everything when I start a new ASP.NET MVC 4 Web Application project. By default when you run this project it creates a LocalDb instance and creates the following tables in it:


  • webpages_Membership

  • webpages_OAuthMembership

  • webpages_Roles

  • webpages_UsersInRoles

  • 用户配置

我已经能够使用code第一次迁移把用户配置表到一个SQL Server数据库。不过,我一直无法与其他4个表来完成。

I have been able to use a code first migration to put the UserProfile table into a SQL server database. However, I have not been able to accomplish this with the other 4 tables.

显然,我的目标是启动一个单独的SQL Server数据库,并拥有所有的表为包含在一个数据库中的应用程序。

Obviously my goal is to start with a single SQL Server database and have all of the tables for the application contained within the single database.

推荐答案

打开InitializeSimpleMembershipAttribute.cs文件,这哪里是WebSecurity数据库初始化。你需要用正确的connectionStringName进行修改。例如:

Open your InitializeSimpleMembershipAttribute.cs file, this is where the WebSecurity database initialization is. You need to modify it with the correct connectionStringName. Example:

修改

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

WebSecurity.InitializeDatabaseConnection("MyRealDBConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

如果您要复制的网络安全表的结构与code先用,有一篇文章....我不能在此刻找到,给我几下。

IF you want to copy the structure of the web security tables to use with Code First, there is an article .... which I cannot find at the moment ... give me a few.

好吧,我无法找到它 - 但说实话 - 这是一个痛苦。最简单的方法,因为你有DB已经产生,可能是使用code首先逆向工程工具,像的实体框架电动工具的。这将做的大部分工作的为您服务。然后,只需将这些类添加到您的DbContext,建立一个迁移和更新您的真正的数据库。

Well I could not find it - but honestly - it was a pain. The easiest way, since you have the DB generated already, might be to use an Code First reverse engineer tool like Entity Framework Power Tools. This will do most of the work for you. Then just add the classes to your DbContext, create a migration, and update your real database.

此外 - 你可能需要做出比这更多的修改 - 取决于上下文姓名和

Also - you may need to make more modifications than this - depending on your Context name and such.

这篇关于有没有一种方法,使EF 5 code第一次移民在ASP.NET MVC 4使用SQL Server数据库的一切?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆