Ejemplo n.º 1
0
 /// <summary>
 /// 初始化一个<see cref="DbContextConfig"/>类型的新实例
 /// </summary>
 internal DbContextConfig(ContextElement element)
 {
     Name                 = element.Name;
     Enabled              = element.Enabled;
     DataLoggingEnabled   = element.DataLoggingEnabled;
     ConnectionStringName = element.ConnectionStringName;
     ContextType          = Type.GetType(element.ContextTypeName);
     InitializerConfig    = new DbContextInitializerConfig(element.DbContextInitializer);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 初始化一个<see cref="DbContextConfig"/>类型的新实例
 /// </summary>
 internal DbContextConfig(ContextElement element)
 {
     Name = element.Name;
     Enabled = element.Enabled;
     DataLoggingEnabled = element.DataLoggingEnabled;
     ConnectionStringName = element.ConnectionStringName;
     ContextType = Type.GetType(element.ContextTypeName);
     InitializerConfig = new DbContextInitializerConfig(element.DbContextInitializer);
 }
Ejemplo n.º 3
0
 private static DbContextInitializerBase CreateInitializer(DbContextInitializerConfig config)
 {
     Type initializerType = config.InitializerType;
     DbContextInitializerBase initializer = Activator.CreateInstance(initializerType) as DbContextInitializerBase;
     if (initializer == null)
     {
         throw new InvalidOperationException(Resources.DatabaseInitializer_TypeNotDatabaseInitializer.FormatWith(initializerType));
     }
     foreach (Assembly mapperAssembly in config.EntityMapperAssemblies)
     {
         if (initializer.MapperAssemblies.Contains(mapperAssembly))
         {
             continue;
         }
         initializer.MapperAssemblies.Add(mapperAssembly);
     }
     dynamic dynamicInitializer = initializer;
     if (config.CreateDatabaseInitializerType != null)
     {
         dynamic createDatabaseInitializer = Activator.CreateInstance(config.CreateDatabaseInitializerType);
         dynamicInitializer.CreateDatabaseInitializer = createDatabaseInitializer;
     }
     return (DbContextInitializerBase)dynamicInitializer;
 }