/// <summary>
        ///
        /// </summary>
        /// <param name="dbOptions"></param>
        /// <param name="options"></param>
        /// <param name="sqlAdapter">数据库适配器</param>
        /// <param name="loggerFactory">日志工厂</param>
        /// <param name="httpContextAccessor"></param>
        protected DbContextOptionsAbstract(DbOptions dbOptions, DbConnectionOptions options, ISqlAdapter sqlAdapter, ILoggerFactory loggerFactory, IHttpContextAccessor httpContextAccessor)
        {
            if (options.Name.IsNull())
            {
                throw new ArgumentNullException(nameof(options.Name), "数据库连接名称未配置");
            }

            if (options.ConnString.IsNull())
            {
                throw new ArgumentNullException(nameof(options.ConnString), "数据库连接字符串未配置");
            }

            DbOptions           = dbOptions;
            Name                = options.Name;
            ConnectionString    = options.ConnString;
            SqlAdapter          = sqlAdapter;
            LoggerFactory       = loggerFactory;
            HttpContextAccessor = httpContextAccessor;

            if (options.EntityTypes != null && options.EntityTypes.Any())
            {
                foreach (var entityType in options.EntityTypes)
                {
                    EntityDescriptorCollection.Add(new EntityDescriptor(entityType, sqlAdapter, new EntitySqlBuilder()));
                }
            }
        }
Ejemplo n.º 2
0
        public void LoadEntityDescriptors()
        {
            var entityTypes = Options.DbModuleOptions.EntityTypes;

            if (entityTypes != null && entityTypes.Any())
            {
                foreach (var entityType in entityTypes)
                {
                    EntityDescriptorCollection.Add(new EntityDescriptor(this, entityType));
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="dbOptions"></param>
        /// <param name="options"></param>
        /// <param name="sqlAdapter">数据库适配器</param>
        /// <param name="loggerFactory">日志工厂</param>
        /// <param name="loginInfo">登录信息</param>
        protected DbContextOptionsAbstract(DbOptions dbOptions, DbModuleOptions options, ISqlAdapter sqlAdapter, ILoggerFactory loggerFactory, ILoginInfo loginInfo)
        {
            if (options.Name.IsNull())
            {
                throw new ArgumentNullException(nameof(options.Name), "数据库连接名称未配置");
            }

            DbOptions       = dbOptions;
            DbModuleOptions = options;
            SqlAdapter      = sqlAdapter;
            LoggerFactory   = loggerFactory;
            LoginInfo       = loginInfo;

            if (options.EntityTypes != null && options.EntityTypes.Any())
            {
                foreach (var entityType in options.EntityTypes)
                {
                    EntityDescriptorCollection.Add(new EntityDescriptor(dbOptions, options, entityType, sqlAdapter));
                }
            }
        }