Code-First Entity Framework - error creating SQL CE DB -


After the

I am using CTT Guthrie and another Scott Hanselman as the outline of the unit with Code-First as CTP (Can not post link, but Google with "Simple Code First Unit Framework 4 - Magic Unicorn feature CTP4"). It's working perfectly for the main MVC application, but now I'm trying to add a test project, which uses a different SQL CE database.

I've added the following to the App.Config file:

  & lt; Connection best & gt; & Lt; Add name = "mydata" connection string = "data source = d: \ myProject \ myDb.sdf;" Provider Name = "System.Data.SqlServerCe.4.0" /> & Lt; / ConnectionStrings & gt;  

However when I try to run this test thrown by trying to create the following error when creating the database:

Test Method MyProjet.Tests.Administration.ModlelTests. Business The TestGate Business List threw an exception: the system. reflection. Target invocation exception: An exception has been thrown to the goal of a greeting. ---> System.TypeInitializationException: type initiator for 'System.Data.SqlServerCe.SqlCeProviderServices' threw an exception --- System.Security.VerificationException: Operation can change runtime unsettled.

with the following stack trace:

System.Data.SqlServerCe.SqlCeProviderServices..ctor () System.Data. SqlServerCe.SqlCeProviderServices..cctor () System.RuntimeFieldHandle.GetValue (RtFieldInfo field, object example, runtime type field type, runtime type delaying type, boolean and domain start) system. Reflections RtFieldInfo.InternalGetValue (object obj, boolean doVisibilityCheck, Boolean doCheckConsistency) System.Reflection.RtFieldInfo.InternalGetValue (Object obj, boolean doVisibilityCheck) System.Reflection.RtFieldInfo.GetValue (object obj) System.Data.SqlServerCe.ExtensionMethods.SystemDataSqlServerCeSqlCeProviderServices_Instance_GetValue () System.Data.SqlServerCe.ExtensionMethods.SystemDataSqlServerCeSqlCeProviderServices_Instance () System.Data.SqlServerCe.SqlCeProviderFactory.System.IServiceProvider.GetS Ervice (type service type) system. Data Common DPProiders Services GETProvider Services (DBPRAIFICTC Factory) System Data Common DP Provider Services GetProvenger Services (DB Connection Connection) System.Data.int. Modell Configuration.INNAL. Configuration. Codefast Cached Metadata Worksspace.GetMedetta Workspace (DB Connection Store Connection) System.Data.Entity.Infrastructure.DbModel.CreateObjectContext [TContext] (DbConnection Existing Connection) System.Data.Entity.Internal.LazyInternalContext.InitializeFromModel (DB Modell Model) System.Data. Entity.Internal.LazyInternalContext.InitializeContext () System.Data Entity.Internal.InternalContext.Initialize () System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (type entityType) System.Data.Entity.Internal.Linq.EfInternalQuery 1.Initialize () System.Data.Entity.Internal .inq.EfInternalQuery 1.Include (string path) System.Data.Entity.Infrastructure.DbQuery1.Include (string path) MyP rojet.Areas.Adminis Tration.Models.BusinessModel.GetBusinesses () in: Projects2010 \ MyProjet \ MyProjet \ \ areas \ Administration \ Model \ BusinessModel.cs: In-line 47 MyProjet.Tests.Administration.ModlelTests.Business.TestGetBusinessesList (): \ projects2010 \ MyProjet \ MyProjet.Tests \ Administration \ ModlelTests \ Business.cs: Line 45

I have tried to replace existing MyData connection string in MVC application, and it works fine. This only causes this problem when the test is added to the project, apart from this, the test project works without any problem, when it is told in a SQL or SQL Express database.

For some time this has been struggled with, and could not understand it. I'm sure I've overlooked something simple.

Try to use

Database. Defactation factor = new SQL Connection Fitterator ("System.Data SQL ServerV4.0");

View my blog post for an example


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -