예제 #1
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);
            }
            return(initializer);
        }
예제 #2
0
 /// <summary>
 /// 注册上下文初始化器
 /// </summary>
 /// <param name="contextType">上下文类型</param>
 /// <param name="initializer">上下文初始化器</param>
 public void RegisterInitializer(DbContextInitializerBase initializer)
 {
     _contextInitializer = initializer;
     initializer.Initialize();
 }
예제 #3
0
        /// <summary>
        /// 获取或设置 实体映射程序集查找器
        ///     必须在配置文件中指定MapperAssembly,暂时不启用“生成默认配置文件”
        /// </summary>
        //public IEntityMapperAssemblyFinder MapperAssemblyFinder { get; set; }

        /// <summary>
        /// 开始初始化数据上下文
        /// </summary>
        /// <param name="config">数据库配置信息</param>
        public virtual void Initialize(DbContextInitializerConfig config)
        {
            DbContextInitializerBase initializer = CreateInitializer(config);

            DbContextManager.Instance.RegisterInitializer(initializer);
        }