Пример #1
0
        /// <summary>
        /// 获得分页数据
        /// </summary>
        /// <param name="repositoryOption"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        private string GetPageSql(RepositoryOption repositoryOption, string sql)
        {
            var resultSql = $"select count(*) from ({sql});";
            var dbName    = repositoryOption.DbConnectionType.FullName;

            if (repositoryOption.IsSqlite)
            {
                resultSql += pageable != null ?
                             $"select * from ({sql}) limit {pageable.PageSize} offset {pageable.PageSize * (pageable.PageNumber - 1)}" :
                             $"select * from ({sql})";
            }
            else if (repositoryOption.IsMysql)
            {
                resultSql  = $"select count(*) from ({sql}) tmp1;";
                resultSql += pageable != null ?
                             $"select * from ({sql}) tmp2 limit {pageable.PageSize * (pageable.PageNumber - 1)},{pageable.PageSize}" :
                             $"select * from ({sql}) tmp2";
            }
            else if (repositoryOption.IsSqlServer)
            {
                resultSql = $"select count(*) from ({sql}) tmp;select * from ({sql}) tmp2";
            }
            else
            {
                throw new Exception("not support");
            }

            return(resultSql);
        }
Пример #2
0
 private void Init()
 {
     //先获得工作单元和数据库工厂以及序列化器
     uow              = ServiceProvider.GetService <IUnitOfWork>();
     dbFactory        = ServiceProvider.GetService <IDbFactory>();
     repositoryOption = ServiceProvider.GetService <RepositoryOption>();
     parameterDictionary.Clear();
     pageable = null;
 }
Пример #3
0
        public BaseRepository(IUnitOfWork uow, IDbFactory dbFactory, RepositoryOption repositoryOption)
        {
            this.uow              = uow;
            this.dbFactory        = dbFactory;
            this.repositoryOption = repositoryOption;

            databaseType = repositoryOption.DatabaseType;

            base.Init(databaseType);
        }
Пример #4
0
 public DbFactory(ILogger <IUnitOfWork> log, RepositoryOption repositoryOption)
 {
     this.log = log;
     this.repositoryOption = repositoryOption;
 }
Пример #5
0
 public DbFactory(RepositoryOption option)
 {
     this.repositoryOption = option;
 }