I have a Visual Studio solution with two projects: MyApp.MvcUI and MyApp.Domain (class library).
MyApp.MvcUI contains my SQL Server CE 4 database.
MyApp.Domain is supposed to contain the Entity Framework EDMX file, but if I add it there I don’t have the option to use SQL Server CE 4, only 3.5.
http://www.codetunnel.com/content/images/sqlce35only.jpg
If I add the EDMX in the MvcUI project then I am able to choose SQL Server CE 4.
Question
-
How can I put my Entity Framework content into the
MyApp.Domainproject and use a SQL Server CE 4 database that lives in theMyApp.MvcUIproject? -
Once I solved that problem, what will the data source portion of my connection string in
App.Configlook like? I know the web project’s connection string will simply look like this:Data Source=|DataDirectory|\CE4DB.sdfbut what will that look like in
App.Configin theMyApp.Domainproject? Will it be an absolute path likeC:\Code\MyProject\MyApp.MvcUI\App_Data\CE4DB.sdf
If so, is there a way to make that a relative path so when people pull the project down from source control it will still work without path corrections?
I tried the suggestions here. My EF was already at the latest version (4.3 as of this post) but I did install SQL Server CE through nuget as well as EntityFramework.SqlServerCompact which says “Allows SQL Server Compact 4.0 to be used with Entity Framework.” Still no option to use CE 4 in the wizard when trying to update the EDMX model from database. If this is all done in the MVC project then I do have the option to use CE 4 in the dialogue box pictured in my question.
I did get it to work though. I simply used a connection string like the one it generates when I put the EDMX in the MVC project.
I was then able to get the EF designer to read from the database. As a bonus the data source path is relative 😀 so other developers pulling down a fresh copy of the project from source control will also be able to use the EF designer straight away without tweaking it. I’m planning to switch to code-first EF soon but I wanted to get this all working with the EDMX first since that’s what I know how to do currently.
Obviously at runtime the connection string in MyApp.Domain does not matter because it reads from the active project’s config file. In this case Web.Config for the MvcUI project. In which the connection string is even easier since the path is simplified.