0
votes

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.

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" />

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.

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

1 Answers

2
votes

Two potential answers:

  1. If I understand your intent you are trying to use two separate DB Contexts and perform queries that join across both of them. This is not possible in Entity Framework (as of this writing) though it may be considered in the future. See this post for more specifics: https://stackoverflow.com/a/8536400/941058

    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.

  2. 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/