Integration Testing Entity Framework code first with in-memory database

Use SQL Compact 4.0 (download both SqlCE and tools by web platform installer) – EF Code first has direct support for that. The only difference will be that your application will use connection string to big SQL Server:

<add name="MyDbContext" 
     provider="System.Data.SqlClient" 
     connectionString=
       "Data Source=...;InitialCatalog=...;Integrated Security=SSPI" />

and your tests will use connection string to SQL Compact:

<add name="MyDbContext" 
     provider="System.Data.SqlServerCe.4.0" 
     connectionString="Data Source=Database.sdf" />

Leave a Comment