Все работало, пока я не решил сделать свой Класс DBConfiguration (унаследованный) был общим, чтобы другие классы DBContext могли использовать его. После этого я начал получать ошибку «не удалось создать экземпляр типа 'repository.contexts.contextConfiguration`1 [repository.contexts.globalcontext]». Тип не должен быть общим. » p> вот [новая] dbconfiguration: < /p>
Код: Выделить всё
using System.Data.Entity;
using System.Data.Entity.SqlServer;
namespace Repository.Contexts
{
// Old impl did not have a constraint. Instead, the type was directly used in the CreateDatabaseIfNotExists's param
public class ContextConfiguration : DbConfiguration where TContext : DbContext
{
public ContextConfiguration()
{
SetDatabaseInitializer(new CreateDatabaseIfNotExists());
SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices.Instance);
}
}
}
< /code>
Конфигурация используется как таковая: < /p>
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
[DbConfigurationType(typeof(ContextConfiguration))]
public class GlobalContext : DbContext
{
// DbSets...
// Constructor...
// OnModelCreating...
}
Подробнее здесь: https://stackoverflow.com/questions/382 ... dbcontexts