移动我的code首先实体框架创建的数据库的默认成员资格提供程序数据库 [英] Move my Code First Entity Framework created database to the Default Membership Provider database

查看:222
本文介绍了移动我的code首先实体框架创建的数据库的默认成员资格提供程序数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我已经建立了一个ASP.NET MVC3应用程序,它有两个数据库。

I have an ASP.NET MVC3 application that I have built and it has two databases.

一个是在参考了默认的成员资格提供程序,当我建立应用程序自动创建。

One is in reference to the Default Membership Provider and was automatically created when I built the app.

另一种是数据库我有一个名为SchoolContext,我想所有在 SchoolContext 的信息存储在同一个数据库中的默认成员资格提供的所有数据。

The other is a database I have named SchoolContext and I would like all the information within SchoolContext to be stored in the same database as all the data in Default Membership Provider.

下面是我的两个连接字符串:

Here are my two connection strings:

<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="SchoolContext" connectionString="Data Source=|DataDirectory|School.sdf" providerName="System.Data.SqlServerCe.4.0" />

我试图重新命名 ApplicationServices SchoolContext 然后注释掉我的第二个连接字符串,我可以加载和登录使用默认的成员资格提供程序就好了,但每当我需要排队的已存储原始 SchoolContext 内信息的数据库,我得到的错误,说明该模型是不存在的,等等。 。和数据不包含从默认成员资格提供的信息的数据库内的建

I tried renaming ApplicationServices to SchoolContext and then commenting out my second connection string and I can load up and "log in" using the default membership provider just fine, but whenever I need to queue the database for information that was stored within the original SchoolContext, I get errors stating that the model is nonexistant, etc. . . and the data is not built within the database that contains the information from the default membership provider.

我使用的是初始重建数据库,如果模型的变化:

I am using an initializer to rebuild the database if the model changes:

public class SchoolInitializer : DropCreateDatabaseIfModelChanges<SchoolContext>

这正常工作任何时候我编辑在模型中的东西,我使用的是两台数据库方案。但是,它不工作时,我想这两个数据库连接成一个。

And this works fine any time I edit something in the model and I am using the two database scheme. However, it is not working when I want to join the two databases into one.

我显然不知道如何将两个数据库连接为我所试图做的是不工作的,我应该如何恰当地设置MVC把我的 SchoolContext 进入同一数据库所需的默认成员资格提供的信息?

I apparently do not know how to connect the two databases as what I am trying to do is not working, how should I appropriately set up mvc to put my SchoolContext into the same database as the information needed for the Default Membership Provider?

推荐答案

两个可能的答案:


  1. 如果我理解你的意图,你要使用两个单独的DB
    上下文和执行跨两者连接查询。这是
    在实体框架不可能(在本文写作),虽然它可能
    在将来被考虑。看到这个帖子了更多的细节:
    http://stackoverflow.com/a/8536400/941058

如果您需要加入一些资料,你需要做的是在内存中
使用LINQ。从本质上讲,你将需要存储外键
查询之一,当任一数据库信息和参考,或
其他。

If you need to join up information you will need to do it in memory using LINQ. Essentially you'll need to store foreign key information in either database and reference it when querying one or the other.

如果你是不是想跨情境加入而只是想使用EF默认成员资格提供这样考虑:
HTTP://efmembership.$c$cplex.com/

If you are not trying to cross-context join but instead just want to use the Default Membership Provider with EF consider this: http://efmembership.codeplex.com/

这篇关于移动我的code首先实体框架创建的数据库的默认成员资格提供程序数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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