2

I am not planning to use EF Code First in an MVC Website. I am looking to Utilize it in a App that has a WPF Client.

Projects are setup as

  • ContactManager.Core // Contains all
    Entities(dll)
  • ContactManager.Data // Contains the DataContext and other data related Services(dll)
  • ContactManager.Services // Business
    components (dll)
  • ContactManager.Client // WPF
    Application

I am unable to generate a SQLExpress or SQLCE 4.0 DB. I am more interested in compact version db. I am not getting any error except my unit tests fail because it tries to connect a db that doesnt exist.

Perpetualcoder
  • 13,501
  • 9
  • 64
  • 99
  • I've you found an answer to this question? I'm trying to do same here! – Gabriel Mongeon Oct 20 '11 at 22:07
  • @GabrielMongeon: I havent found a way to do this.. – Perpetualcoder Oct 21 '11 at 03:40
  • I manage to make it work with SQLExpress with this walkthrough: http://blogs.msdn.com/b/adonet/archive/2011/03/08/ef-feature-ctp5-code-first-model-with-master-detail-wpf-application.aspx. Now I'll figure out what is needed to make it work with SQLCE, I'm guessing something in the App.Config should do the trick. I'll keep you posted! – Gabriel Mongeon Oct 21 '11 at 13:47

1 Answers1

1

I found out the answer 2 Options:

Option 1:

In your DbContext you specify the connection strings in the base constructor:

public class RecetteContext : DbContext
{
    public RecetteContext()
        :base("<YourConnectionString HERE>")
    {
    }

    public DbSet<Categorie> Categories { get; set; }
    public DbSet<Recette> Recettes { get; set; }

    }
}

Option 2:

The one I used, you give you connection string a name in the DbContext base constructor:

public RecetteContext()
    : base("RecettesDatabase")
{            }

And in your App.Config file you add a ConnectionString with the same name:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="RecettesDatabase"
         connectionString="Data Source=RecettesDB.sdf"
         providerName="System.Data.SqlServerCe.4.0"/>
  </connectionStrings>
</configuration>

Hope it solved your issue!

Gabriel Mongeon
  • 7,251
  • 3
  • 32
  • 35