EF DBConfiguration associated automatically to DBContext without annotation

c# dbcontext entity-framework


use EF 6.1.1, the most recent version, and EF for SQL Server Compact 6.1.1, which incorporates Compact 4.0. Goal is Net 4.5.

I want to code up my EF and then use StructureMap to put it together. made a class called DbConfiguration

 public class MyConfiguration : DbConfiguration
   SetDatabaseInitializer<MyContext>(new MyInitializer());

and a setting

 public class MyContext : DbContext
   public MyContext(String connection) : base(connection) {}

In XUnit, I execute:

 using (var ctx = new MyContext(String.Format("Data Source={0}", Path.Combine(databasePath, databaseName)))) {

My Compact database is successfully created (and seeded via the initializer) by the test case. But there's a lot of implicit activity going on that I'm not aware of.

I don't require the following annotation on my MyContext class, for instance:


EF must be capable of recognizing and utilizing the MyConfiguration class that I have created and extends DbConnection. Or? Additionally, even if I completely remove MyConfiguration, the test case will still create a database (obviously not seeded). How?

I'd prefer to be able to use code to directly assign a DbConfiguration to a particular DbContext rather than using static:

 static MyContext()
   DbConfiguration.set(new MyConfiguration());

The rationale for this is to support several "profiles" with StructureMap. Any thoughts?

9/22/2014 9:20:20 AM

Accepted Answer

9/22/2014 1:10:26 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow