I use Entity Framework CTP with Code-First, as in this tutorial by Scott Guthrie and another Scott Hanselman (cannot post the link, but google "Simple Code First with Entity Framework 4 - Magic Unicorn Feature CTP 4"). This works fine for the main MVC application, but now I'm trying to add a testing project that uses a separate SQL CE database.
I added the following to the App.Config file:
<connectionStrings>
<add name="MyData"
connectionString="Data Source=D:\myProject\myDb.sdf;"
providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
However, when I try to run the tests, when I try to create a database, it creates the following error:
Test method MyProjet.Tests.Administration.ModlelTests.Business.TestGetBusinessesList threw an exception: System.Reflection.TargetInvocationException: The exception was caused by the purpose of the call. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlServerCe.SqlCeProviderServices' threw an exception. ---> System.Security.VerificationException: Operation may destabilize at runtime.
With the following stack trace:
System.Data.SqlServerCe.SqlCeProviderServices..ctor() System.Data.SqlServerCe.SqlCeProviderServices..cctor() System.RuntimeFieldHandle.GetValue(RtFieldInfo , , RuntimeType fieldType, RuntimeType declaringType, & domainInitialized) System.Reflection.RtFieldInfo.InternalGetValue( obj, Boolean doVisibilityCheck, Boolean doCheckConsistency) System.Reflection.RtFieldInfo.InternalGetValue( obj, Boolean doVisibilityCheck) System.Reflection.RtFieldInfo.GetValue( OBJ) System.Data.SqlServerCe.ExtensionMethods.SystemDataSqlServerCeSqlCeProviderServices_Instance_GetValue() System.Data.SqlServerCe.ExtensionMethods.SystemDataSqlServerCeSqlCeProviderServices_Instance() System.Data.SqlServerCe.SqlCeProviderFactory.System.IServiceProvider.GetService( ) System.Data.Common.DbProviderServices.GetProviderServices(DbProviderFactory factory) System.Data.Common.DbProviderServices.GetProviderServices(DbConnection ) System.Data.Entity.ModelConfiguration.Internal.Configuration.CodeFirstCachedMetadataWorkspace.GetMetadataWorkspace(DbConnection storeConnection) System.Data.Entity.Infrastructure.DbModel.CreateObjectContext [TContext] (DbConnection existingConnection) System.Data.Entity.Internal.LazyInternalContext.InitializeFromModel(DbModel ) System.Data.Entity.Internal.LazyInternalContext.InitializeContext() System.Data.Entity.Internal.InternalContext.Initialize() System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType( ) System.Data.Entity.Internal.Linq.EfInternalQuery 1.Initialize()
System.Data.Entity.Internal.Linq.EfInternalQuery 1.Include(String ) System.Data.Entity.Infrastructure.DbQuery`1.Include(String ) MyProjet.Areas.Administration.Models.BusinessModel.GetBusinesses() D:\projects2010\MyProjet\MyProjet\\\Models\BusinessModel.cs: 47 MyProjet.Tests.Administration.ModlelTests.Business.TestGetBusinessesList() D:\projects2010\MyProjet\MyProjet.Tests\\ModlelTests\Business.cs: 45
MyData MVC, . , . , SQL SQL Express.
- . , - .