如何IdentityUser表迁移到asp.net mvc的5现有的数据库? [英] How to migrate IdentityUser tables to an existing database in asp.net mvc 5?

查看:258
本文介绍了如何IdentityUser表迁移到asp.net mvc的5现有的数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1)从办公室的SQL服务器上,挤满了数据。 2)一个全新的asp.net的MVC 5从默认模板,其中包括IdentityUser及其表。WEBAPPLICATION

I have 1) an SQL server from the office, packed with data. 2) a brand new asp.net mvc 5 Webapplication from default template, which includes the IdentityUser and its tables.

我们的目标是通过IdentityUser表到办公室服务器,以拥有这一切在一个地方。

The goal is to pass IdentityUser tables to the office server in order to have it all in one place.

使用实体框架,我能够从服务器拉表,并创建基本的模型。同时,数据库连接制成,用的Web.config文档这里面的连接字符串:

Using Entity Framework, I was able to pull the tables from server and to create basic models. Meanwhile, a database connection was made, with this connection string inside Web.config doc:

<add name="MyOfficeEntities" connectionString="metadata=res://*/Models.MyOffice.csdl|res://*/Models.MyOffice.ssdl|res://*/Models.MyOffice.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=193.148.0.105;initial catalog=MyOfficeVCSPT;user id=myUser;password=myPassword;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

后来,在IdentityModels,其中放置现在数据库的背景下,我改变基地正常DefaulConnection这样:

Later, at IdentityModels, where is placed for now the Database context, I changed base for the normal DefaulConnection to this:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("MyOfficeEntities", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}

所以,我创建了一个名为AddIdentityUsersToMyOfficeDatabase和迁移,当运行它时,Visual Studio在本地服务器上创建另一个数据库(SQL防爆preSS)呼吁MyOfficeEntities和我的表结束错位。

So, I created a migration called AddIdentityUsersToMyOfficeDatabase and, when run it, Visual Studio creates another database at local server (SQL Express) called MyOfficeEntities and my tables end misplaced.

如果我删除throwIfV1Schema:假的,从这一行::基地(MyOfficeEntities,throwIfV1Schema:假的),我得到了在控制台的错误:

If I remove the throwIfV1Schema: false, from this line: : base("MyOfficeEntities", throwIfV1Schema: false), I got an error at console:

创建DbModelBuilder或创建的DbContext写EDMX
  不支持使用数据库优先或模型优先。 EDMX只能是
  从$ C $获得C首先的DbContext不使用创建的现有
  DbCompiledModel。

Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.

所以,再次¿我怎么打发IdentityUser表SQL MyOfficeServer?我所知道的是如此简单,但是是我的第一asp.net项目。

So, again, ¿how do I pass the IdentityUser tables to SQL MyOfficeServer? I know is so basic, but is my first asp.net project.

先谢谢了。

推荐答案

解释more.haveüSQL Server上的表,美希望通过code创建数据库表的第一?

explain more.have u a table on sql server that u want create table on database by code first ?

这篇关于如何IdentityUser表迁移到asp.net mvc的5现有的数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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