0

I want two database and two context. One for ASP.NET MVC based project (With SQL Server) and one for windows application based project admin management tools (With SQL Server CE). my Solution structure like below:

MySolution
--DataAccessLayer (Class Library Project)
--ModelProject (Class Library Project)
--MyWebApplication (ASP.NET MVC Project with SQL Server)
--MyAdminTools (Windows Application Project with SQL Server CE)

I store POCO class files in ModelProject. Some of this POCO class was shared in two database so I create DataAccessLayerProject with two context both of them were inherited from DbContext and I set connection string in constructor like below:

public MyWebApplicationContext()
            : base("WebDB")
    {
    }
public AdminToolsContext()
            : base("AdminToolsDB")
    {
    }

and this is connection strings:

<add name="WebDB" connectionString="Data Source=localhost;Initial Catalog=WebDB;persist security info=True;user id=sa;password=123;" providerName="System.Data.SqlClient" />
<add name="AdminToolsDB" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|\AdminToolsDB.sdf" />

I also enable migration for my context step by step with this post guidance

Now I have two questions:

First: Is this the correct structure for store project and solution in separate project?? (context and model in separate project)

Second: In above steps everything is right except SQL Server CE database. when I run update-database for my SQL Server CE context, Package Manager Console print a message that update and seeding data done successfully but AdminToolsDB.sdf not created in DataAccessLayer bin/Debug folder. I also search for this file in entire solution folder but no file exist. Where is the problem?

Community
  • 1
  • 1
b24
  • 2,425
  • 6
  • 30
  • 51
  • possible duplicate of [SQL Server CE Code First migrations problems](http://stackoverflow.com/questions/16131193/sql-server-ce-code-first-migrations-problems) – Gert Arnold Jan 03 '14 at 09:10
  • No I add |DataDirectory| to prevent that issue. – b24 Jan 03 '14 at 10:54
  • close solution http://stackoverflow.com/questions/20354083/ef6-and-multiple-configurations-sql-server-and-sql-server-compact – phil soady Jan 03 '14 at 14:26
  • CFM only supports on DbContext per project. Your situation may be beyond the limitations of CFM if you require the two DBs to be different. – Adrian Jan 23 '14 at 19:28

0 Answers0