Ejemplo n.º 1
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static DbTable CreateORMTable(IRepositoryInternal repo)
        {
            var em = repo.EntityMeta;

            if (em.TableMeta == null)
            {
                throw new ORMException(string.Format("类型 {0} 没有映射数据库,无法为其创造 ORM 运行时对象。", em.EntityType.FullName));
            }

            DbTable res = null;

            switch (repo.RdbDataProvider.DbSetting.ProviderName)
            {
            case DbSetting.Provider_SqlClient:
                res = new SqlTable(repo);
                break;

            case DbSetting.Provider_SqlCe:
                res = new SqlCeTable(repo);
                break;

            case DbSetting.Provider_Oracle:
                res = new OracleTable(repo);
                break;

            default:
                throw new NotSupportedException();
            }

            ProcessManagedProperties(em.EntityType, res, em);

            return(res);
        }
Ejemplo n.º 2
0
 internal RdbTable(IRepositoryInternal repository)
 {
     _repository = repository;
     _meta = repository.EntityMeta;
     _tableInfo = repository.TableInfo;
     _columns = new List<RdbColumn>();
 }
Ejemplo n.º 3
0
 internal RdbTable(IRepositoryInternal repository)
 {
     _repository = repository;
     _meta       = repository.EntityMeta;
     _tableInfo  = repository.TableInfo;
     _columns    = new List <RdbColumn>();
 }
Ejemplo n.º 4
0
 public PersistanceTableInfo(IRepositoryInternal repo)
 {
     _repo        = repo;
     this.Class   = repo.EntityType;
     this.Name    = repo.EntityMeta.TableMeta.TableName;
     this.Columns = new List <PersistanceColumnInfo>();
 }
Ejemplo n.º 5
0
 public PersistanceTableInfo(string name, IRepositoryInternal repo)
 {
     _repo        = repo;
     this.Name    = name;
     this.Class   = repo.EntityType;
     this.Columns = new List <PersistanceColumnInfo>();
 }
Ejemplo n.º 6
0
 public PersistanceTableInfo(IRepositoryInternal repo)
 {
     _repo = repo;
     this.Class = repo.EntityType;
     this.Name = repo.EntityMeta.TableMeta.TableName;
     this.Columns = new List<PersistanceColumnInfo>();
 }
Ejemplo n.º 7
0
 internal DbTable(IRepositoryInternal repository)
 {
     _repository = repository;
     _meta       = repository.EntityMeta;
     _name       = _meta.TableMeta.TableName;
     _columns    = new List <DbColumn>();
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static RdbTable CreateORMTable(IRepositoryInternal repo)
        {
            RdbTable table = null;

            var provider = RdbDataProvider.Get(repo).DbSetting.ProviderName;
            switch (provider)
            {
                case DbSetting.Provider_SqlClient:
                    table = new SqlServerTable(repo);
                    break;
                case DbSetting.Provider_SqlCe:
                    table = new SqlCeTable(repo);
                    break;
                default:
                    if (DbConnectionSchema.IsOracleProvider(provider))
                    {
                        table = new OracleTable(repo);
                        break;
                    }
                    throw new NotSupportedException();
            }

            var em = repo.EntityMeta;
            foreach (var columnInfo in table.Info.Columns)
            {
                //生成 ManagedPropertyBridge
                var epm = em.Property(columnInfo.Property);
                if (epm == null) { throw new ArgumentNullException(string.Format("{0}.{1} 属性需要使用托管属性进行编写。", table.Info.Class.FullName, columnInfo.Property.Name)); }

                var column = table.CreateColumn(columnInfo);
                table.Add(column);
            }

            return table;
        }
Ejemplo n.º 9
0
        protected virtual RdbTable CreateRdbTableCore(IRepositoryInternal repo, string dbProvider)
        {
            switch (dbProvider)
            {
            case DbSetting.Provider_SqlClient:
                return(new SqlServerTable(repo, dbProvider));

            case DbSetting.Provider_SqlCe:
                return(new SqlCeTable(repo, dbProvider));

            case DbSetting.Provider_SQLite:
                return(new SQLiteTable(repo, dbProvider));

            case DbSetting.Provider_MySql:
                return(new MySqlTable(repo, dbProvider));

            default:
                if (DbConnectionSchema.IsOracleProvider(dbProvider))
                {
                    return(new OracleTable(repo, dbProvider));
                }
                break;
            }

            throw new NotSupportedException();
        }
Ejemplo n.º 10
0
        public RdbTable CreateRdbTable(IRepositoryInternal repo)
        {
            RdbTable table = null;

            var provider = RdbDataProvider.Get(repo).DbSetting.ProviderName;

            table = this.CreateRdbTableCore(repo, provider);

            table.IdentifierProvider = DbMigrationProviderFactory.GetIdentifierProvider(provider);
            table.DbTypeConverter    = DbMigrationProviderFactory.GetDbTypeConverter(provider);

            var em = repo.EntityMeta;

            foreach (var columnInfo in table.Info.Columns)
            {
                var epm = em.Property(columnInfo.Property);
                if (epm == null)
                {
                    throw new ArgumentNullException(string.Format("{0}.{1} 属性需要使用托管属性进行编写。", table.Info.EntityType.FullName, columnInfo.Property.Name));
                }

                var column = table.CreateColumn(columnInfo);

                table.Add(column);
            }

            return(table);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 通过目前已经收集到的属性、操作符、值,来生成一个属性条件结果。
 /// 并清空已经收集的信息。
 /// </summary>
 private void MakeConstraint()
 {
     if (_propertyResult != null && _operator.HasValue)
     {
         if (_hasValueResult)
         {
             _whereResult = new PropertyConstraint
             {
                 Context      = _query,
                 Property     = _propertyResult,
                 ConcreteType = _propertyResultRepo.EntityType,
                 Operator     = _operator.Value,
                 Value        = _valueResult
             };
             _hasValueResult = false;
         }
         else
         {
             _whereResult = new TwoPropertiesConstraint
             {
                 Context            = _query,
                 LeftProperty       = _propertyResult,
                 LeftPropertyOwner  = _propertyResultRepo.EntityType,
                 Operator           = _operator.Value,
                 RightProperty      = _rightPropertyResult,
                 RightPropertyOwner = _rightPropertyResultRepo.EntityType,
             };
             _rightPropertyResult     = null;
             _rightPropertyResultRepo = null;
         }
         _propertyResult     = null;
         _propertyResultRepo = null;
         _operator           = null;
     }
 }
        public DatabaseContext(string dataSourceHost, string databaseName, string databaseUser, string databasePassword, string authenticationDatabaseName)
        {
            ArgumentValidation.ValidateString(dataSourceHost, nameof(dataSourceHost));
            ArgumentValidation.ValidateString(databaseName, nameof(databaseName));
            ArgumentValidation.ValidateString(databaseUser, nameof(databaseUser));
            ArgumentValidation.ValidateString(databasePassword, nameof(databasePassword));

            var sharedSettings = new MongoConnectionOptions
            {
                MongoDbHost          = dataSourceHost,
                MongoDbUsername      = databaseUser,
                MongoDbPassword      = databasePassword,
                DatabaseName         = databaseName,
                AuthenticationSource = authenticationDatabaseName
            };

            _repositoryClient = new MongoRepositoryClient(sharedSettings);
            _repository       = (IRepositoryInternal)_repositoryClient.GetRepository(databaseName);

            CkEntities           = _repository.GetCollection <CkEntity>();
            CkAttributes         = _repository.GetCollection <CkAttribute>();
            CkEntityAssociations = _repository.GetCollection <CkEntityAssociation>();
            CkEntityInheritances = _repository.GetCollection <CkEntityInheritance>();
            RtAssociations       = _repository.GetCollection <RtAssociation>();
        }
Ejemplo n.º 13
0
        public SQLColumnsGenerator(IRepositoryInternal repository)
        {
            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            this._repository = repository;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 构造函数 初始化仓库对象
        /// </summary>
        /// <param name="repository">仓库对象</param>
        public MySqlTable(IRepositoryInternal repository) : base(repository)
        {
            _insertSql = new Lazy <string>(() =>
            {
                var generatedSql = this.GenerateInsertSQL(false);
                return($@"{generatedSql};
SELECT @@IDENTITY;");
            });
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 构造函数 初始化仓库对象
        /// </summary>
        /// <param name="repository">仓库对象</param>
        /// <param name="dbProvider"></param>
        public SQLiteTable(IRepositoryInternal repository, string dbProvider) : base(repository, dbProvider)
        {
            _insertSql = new Lazy <string>(() =>
            {
                //https://www.cnblogs.com/keitsi/p/5558985.html
                var generatedSql = this.GenerateInsertSQL(false);
                return($@"{generatedSql};
SELECT LAST_INSERT_ROWID() FROM [{this.Name}]");
            });
        }
Ejemplo n.º 16
0
        internal RdbTable(IRepositoryInternal repository)
        {
            _repository = repository;
            _meta       = repository.EntityMeta;
            _tableInfo  = repository.TableInfo;
            _columns    = new List <RdbColumn>();

            _deleteSql       = new Lazy <string>(this.GenerateDeleteSQL, false);
            _updateSQL       = new Lazy <string>(() => this.GenerateUpdateSQL(null), false);
            _insertSql       = new Lazy <string>(() => this.GenerateInsertSQL(false), false);
            _insertSqlWithId = new Lazy <string>(() => this.GenerateInsertSQL(true), false);
        }
Ejemplo n.º 17
0
        internal RdbTable(IRepositoryInternal repository, string dbProvider)
        {
            _repository = repository;
            _meta       = repository.EntityMeta;
            _tableInfo  = RdbTableInfoFactory.CreateTableInfo(_meta, dbProvider);
            _columns    = new List <RdbColumn>();

            _deleteSql       = new Lazy <string>(this.GenerateDeleteSQL);
            _updateSQL       = new Lazy <string>(() => this.GenerateUpdateSQL(null));
            _insertSql       = new Lazy <string>(() => this.GenerateInsertSQL(false));
            _insertSqlWithId = new Lazy <string>(() => this.GenerateInsertSQL(true));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static IPersistanceTableInfo CreateTableInfo(IRepositoryInternal repo)
        {
            var em = repo.EntityMeta;
            if (em.TableMeta == null)
            {
                throw new ORMException(string.Format("类型 {0} 没有映射数据库,无法为其创造 ORM 运行时对象。", em.EntityType.FullName));
            }

            var res = new PersistanceTableInfo(repo);

            ProcessManagedProperties(em.EntityType, res, em);

            return res;
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static RdbTable CreateORMTable(IRepositoryInternal repo)
        {
            RdbTable table = null;

            var provider = RdbDataProvider.Get(repo).DbSetting.ProviderName;

            switch (provider)
            {
            case DbSetting.Provider_SqlClient:
                table = new SqlServerTable(repo);
                break;

            case DbSetting.Provider_SqlCe:
                table = new SqlCeTable(repo);
                break;

            case DbSetting.Provider_MySql:
                table = new MySqlTable(repo);
                break;

            default:
                if (DbConnectionSchema.IsOracleProvider(provider))
                {
                    table = new OracleTable(repo);
                    break;
                }
                throw new NotSupportedException();
            }

            table.IdentifierProvider = DbMigrationProviderFactory.GetIdentifierProvider(provider);
            table.DbTypeConverter    = DbMigrationProviderFactory.GetDbTypeConverter(provider);

            var em = repo.EntityMeta;

            foreach (var columnInfo in table.Info.Columns)
            {
                var epm = em.Property(columnInfo.Property);
                if (epm == null)
                {
                    throw new ArgumentNullException(string.Format("{0}.{1} 属性需要使用托管属性进行编写。", table.Info.Class.FullName, columnInfo.Property.Name));
                }

                var column = table.CreateColumn(columnInfo);

                table.Add(column);
            }

            return(table);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static IPersistanceTableInfo CreateTableInfo(IRepositoryInternal repo)
        {
            var em = repo.EntityMeta;

            if (em.TableMeta == null)
            {
                throw new ORMException(string.Format("类型 {0} 没有映射数据库,无法为其创造 ORM 运行时对象。", em.EntityType.FullName));
            }

            var res = new PersistanceTableInfo(repo);

            ProcessManagedProperties(em.EntityType, res, em);

            return(res);
        }
Ejemplo n.º 21
0
        public SqlServerTable(IRepositoryInternal repository, string dbProvider) : base(repository, dbProvider)
        {
            _insertSql = new Lazy <string>(() =>
            {
                var generatedSql = this.GenerateInsertSQL(false);
                return($@"{generatedSql};
SELECT @@IDENTITY;");
            });
            _insertSqlWithId = new Lazy <string>(() =>
            {
                var generatedSql = this.GenerateInsertSQL(true);
                return($@"SET IDENTITY_INSERT {this.Name} ON;
{generatedSql};
SET IDENTITY_INSERT {this.Name} OFF;");
            });
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 批量插入大量实体
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="entityList">The entity list.</param>
        /// <exception cref="System.ArgumentOutOfRangeException"></exception>
        /// <exception cref="System.ArgumentNullException">只支持 SqlServer</exception>
        private static void AddBatch(IRepositoryInternal repository, IList <Entity> entityList)
        {
            if (entityList.Count < 1)
            {
                throw new ArgumentOutOfRangeException();
            }

            var connection = repository.RdbDataProvider.CreateDbAccesser().Connection;
            var tableInfo  = repository.RdbDataProvider.DbTable;

            var sqlCon = connection as SqlConnection;

            if (sqlCon == null)
            {
                throw new ArgumentNullException("只支持 SqlServer");
            }
            new BatchInsert(entityList, sqlCon, tableInfo).Execute();
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static IPersistanceTableInfo CreateTableInfo(IRepositoryInternal repo)
        {
            var em = repo.EntityMeta;

            if (em.TableMeta == null)
            {
                throw new ORMException(string.Format("类型 {0} 没有映射数据库,无法为其创造 ORM 运行时对象。", em.EntityType.FullName));
            }

            var dbSetting          = RdbDataProvider.Get(repo).DbSetting;
            var identifierProvider = DbMigrationProviderFactory.GetIdentifierProvider(dbSetting.ProviderName);
            var dbTypeConverter    = DbMigrationProviderFactory.GetDbTypeConverter(dbSetting.ProviderName);

            var name = identifierProvider.Prepare(repo.EntityMeta.TableMeta.TableName);
            var res  = new PersistanceTableInfo(name, repo);

            ProcessManagedProperties(em.EntityType, res, em, identifierProvider, dbTypeConverter);

            return(res);
        }
Ejemplo n.º 24
0
        private void VisitValueProperty(PropertyInfo clrProperty, IManagedProperty mp, IRepositoryInternal mpOwnerRepo)
        {
            //接下来,是一般属性的处理
            if (_visitRefProperties)
            {
                throw OperationNotSupported(string.Format("不支持使用属性:{0}。这是因为它的拥有者是一个值属性,值属性只支持直接对比。", clrProperty.Name));
            }

            //如果已经记录了条件的属性,那么当前的 mp 就是用于对比的第二个属性。(A.Code = A.Name 中的 Name)
            if (_propertyResult != null)
            {
                _rightPropertyResult     = mp;
                _rightPropertyResultRepo = mpOwnerRepo;
            }
            //如果还没有记录属性,说明当前条件要比较的属性就是 mp;(A.Code = 1 中的 Code)
            else
            {
                _propertyResult     = mp;
                _propertyResultRepo = mpOwnerRepo;
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static RdbTable CreateORMTable(IRepositoryInternal repo)
        {
            RdbTable table = null;

            switch (RdbDataProvider.Get(repo).DbSetting.ProviderName)
            {
            case DbSetting.Provider_SqlClient:
                table = new SqlTable(repo);
                break;

            case DbSetting.Provider_SqlCe:
                table = new SqlCeTable(repo);
                break;

            case DbSetting.Provider_Oracle:
                table = new OracleTable(repo);
                break;

            default:
                throw new NotSupportedException();
            }

            var em = repo.EntityMeta;

            foreach (var columnInfo in table.Info.Columns)
            {
                //生成 ManagedPropertyBridge
                var epm = em.Property(columnInfo.Property);
                if (epm == null)
                {
                    throw new ArgumentNullException(string.Format("{0}.{1} 属性需要使用托管属性进行编写。", table.Info.Class.FullName, columnInfo.Property.Name));
                }

                var column = table.CreateColumn(columnInfo);
                table.Add(column);
            }

            return(table);
        }
Ejemplo n.º 26
0
        private void VisitValueProperty(PropertyInfo clrProperty, IManagedProperty mp, IRepositoryInternal mpOwnerRepo)
        {
            //接下来,是一般属性的处理
            if (_visitRefProperties)
            {
                throw OperationNotSupported(string.Format("不支持使用属性:{0}。这是因为它的拥有者是一个值属性,值属性只支持直接对比。", clrProperty.Name));
            }

            //如果已经记录了条件的属性,那么当前的 mp 就是用于对比的第二个属性。(A.Code = A.Name 中的 Name)
            if (_propertyResult != null)
            {
                _rightPropertyResult = mp;
                _rightPropertyResultRepo = mpOwnerRepo;
            }
            //如果还没有记录属性,说明当前条件要比较的属性就是 mp;(A.Code = 1 中的 Code)
            else
            {
                _propertyResult = mp;
                _propertyResultRepo = mpOwnerRepo;
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// 通过目前已经收集到的属性、操作符、值,来生成一个属性条件结果。
 /// 并清空已经收集的信息。
 /// </summary>
 private void MakeConstraint()
 {
     if (_propertyResult != null && _operator.HasValue)
     {
         if (_hasValueResult)
         {
             _whereResult = new PropertyConstraint
             {
                 Context = _query,
                 Property = _propertyResult,
                 ConcreteType = _propertyResultRepo.EntityType,
                 Operator = _operator.Value,
                 Value = _valueResult
             };
             _hasValueResult = false;
         }
         else
         {
             _whereResult = new TwoPropertiesConstraint
             {
                 Context = _query,
                 LeftProperty = _propertyResult,
                 LeftPropertyOwner = _propertyResultRepo.EntityType,
                 Operator = _operator.Value,
                 RightProperty = _rightPropertyResult,
                 RightPropertyOwner = _rightPropertyResultRepo.EntityType,
             };
             _rightPropertyResult = null;
             _rightPropertyResultRepo = null;
         }
         _propertyResult = null;
         _propertyResultRepo = null;
         _operator = null;
     }
 }
Ejemplo n.º 28
0
 public SqlOraTable(IRepositoryInternal repository)
     : base(repository)
 {
 }
Ejemplo n.º 29
0
 /// <summary>
 /// 为某个指定的仓库对象构造一个 DbTable
 /// </summary>
 /// <param name="repo"></param>
 /// <returns></returns>
 internal static RdbTable CreateORMTable(IRepositoryInternal repo)
 {
     return(Current.CreateRdbTable(repo));
 }
Ejemplo n.º 30
0
 public SqlCeTable(IRepositoryInternal repository, string dbProvider) : base(repository, dbProvider)
 {
 }
Ejemplo n.º 31
0
 internal EntityQueryBuilder(IRepositoryInternal repo, bool reverseWhere)
 {
     _repo         = repo;
     _reverseWhere = reverseWhere;
 }
Ejemplo n.º 32
0
 public SqlTable(IRepositoryInternal repository) : base(repository)
 {
 }
Ejemplo n.º 33
0
 internal PropertyQuery(IRepositoryInternal repo)
 {
     this._orders = new List<DbOrder>(1);
     _repo = repo;
     _where = this.New();
 }
Ejemplo n.º 34
0
        public SQLColumnsGenerator(IRepositoryInternal repository)
        {
            if (repository == null) throw new ArgumentNullException("repository");

            this._repository = repository;
        }
Ejemplo n.º 35
0
 public EntityQueryBuilder(IRepositoryInternal repo)
     : this(repo, false)
 {
 }
Ejemplo n.º 36
0
 internal PropertyQuery(IRepositoryInternal repo)
 {
     this._orders = new List <DbOrder>(1);
     _repo        = repo;
     _where       = this.New();
 }
Ejemplo n.º 37
0
 internal EntityQueryBuilder(IRepositoryInternal repo, bool reverseWhere)
 {
     _repo = repo;
     _reverseWhere = reverseWhere;
 }
Ejemplo n.º 38
0
 public OracleTable(IRepositoryInternal repository) : base(repository)
 {
 }
Ejemplo n.º 39
0
 public EntityQueryBuilder(IRepositoryInternal repo) : this(repo, false)
 {
 }
Ejemplo n.º 40
0
 public SqlServerTable(IRepositoryInternal repository)
     : base(repository)
 {
 }
Ejemplo n.º 41
0
 public OracleTable(IRepositoryInternal repository)
     : base(repository)
 {
 }