I have a asp.net MVC3 project using EF code-first. For my unit testing I have been using SQL Server CE 4.0 and SQL Server 2008 Express. Both have worked perfectly with EF ge
If you're using EF 6 (just released) you have an alternative.
You can use the new dependency resolution feature to register an implementation of IManifestTokenResolver (described in this preview documentation as IManifestTokenService).
This article gives a bit more information on how to use DbConfiguration. The easiest way to use it is like this:
DbConfigurationType(typeof(EntityFrameworkDbConfiguration))]
public class MyContextContext : DbContext
{
}
This example avoids any trip to the database when building the metadata for SQL Server connections, and automatically specifies SQL Server 2005 compatability.
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Infrastructure.DependencyResolution;
using System.Data.SqlClient;
///
/// A configuration class for SQL Server that specifies SQL 2005 compatability.
///
internal sealed class EntityFrameworkDbConfiguration : DbConfiguration
{
///
/// The provider manifest token to use for SQL Server.
///
private const string SqlServerManifestToken = @"2005";
///
/// Initializes a new instance of the class.
///
public EntityFrameworkDbConfiguration()
{
this.AddDependencyResolver(new SingletonDependencyResolver(new ManifestTokenService()));
}
///
private sealed class ManifestTokenService : IManifestTokenResolver
{
///
/// The default token resolver.
///
private static readonly IManifestTokenResolver DefaultManifestTokenResolver = new DefaultManifestTokenResolver();
///
public string ResolveManifestToken(DbConnection connection)
{
if (connection is SqlConnection)
{
return SqlServerManifestToken;
}
return DefaultManifestTokenResolver.ResolveManifestToken(connection);
}
}
}