private DapperSqlSegment GenerateCountSql(QueryFilter filter) { var sql = new DapperSqlSegment(); var whereSeg = Context.Runtime.SqlGenerator.GenerateFilter <T>(filter, sql.Parameters); sql.Sql = string.IsNullOrWhiteSpace(whereSeg) ? $"SELECT COUNT(*) FROM {this.Context.Runtime.DelimitIdentifier(typeof(T), this._metadata.TableName)}" : $"SELECT COUNT(*) FROM {this.Context.Runtime.DelimitIdentifier(typeof(T), this._metadata.TableName)} WHERE {whereSeg}"; return(sql); }
private DapperSqlSegment GenerateQuerySql(QueryFilter filter) { var sql = new DapperSqlSegment(); var segments = Context.Runtime.GetCrudSegments(this.EntityType); sql.Sql = segments.SelectSql; var whereSeg = Context.Runtime.SqlGenerator.GenerateFilter <T>(filter, sql.Parameters); if (string.IsNullOrWhiteSpace(whereSeg)) { return(sql); } sql.Sql = $"{sql.Sql} WHERE {whereSeg}"; return(sql); }
private DapperSqlSegment GenerateQueryInSql(string field, IEnumerable <Object> values) { var sql = new DapperSqlSegment(); var segments = Context.Runtime.GetCrudSegments(this.EntityType); sql.Sql = segments.SelectSql; var inSeg = Context.Runtime.SqlGenerator.GenerateInClause <T>(field, values, sql.Parameters); if (string.IsNullOrWhiteSpace(inSeg)) { return(sql); } sql.Sql = $"{sql.Sql} WHERE {inSeg}"; return(sql); }
private DapperSqlSegment GeneratePaginationSql(int pageIndex, int pageSize, QueryFilter filter, SortOptions options) { DapperSqlSegment segment = new DapperSqlSegment(); options = options ?? new SortOptions(this._metadata.Fields.First(f => f.IsKey).Name); var segments = Context.Runtime.GetCrudSegments(this.EntityType); string select = segments.SelectSql; string where = filter != null?Context.Runtime.SqlGenerator.GenerateFilter <T>(filter, segment.Parameters) : null; string order = Context.Runtime.SqlGenerator.GenerateOrderBy <T>(options); segment.Sql = Context.Runtime.GetDataSource(typeof(T)).DatabaseProvider.BuildPaginationTSql(pageIndex, pageSize, select, order, where); return(segment); }
private DapperSqlSegment GenerateUpdateSql(QueryFilter filter, IEnumerable <KeyValuePair <String, Object> > fieldsToUpdate) { var segment = new DapperSqlSegment(); if (!fieldsToUpdate.Any()) { throw new ArgumentException($"{typeof(IRepository<>).FullName}.{nameof(Update)} 方法的 {nameof(fieldsToUpdate)} 参数不可为 null 或空字典,如更新整个实体,考虑使用不包含 {nameof(fieldsToUpdate)} 参数的 {nameof(Update)} 重载方法。"); } string tableName = Context.Runtime.GetMetadata(this.EntityType).TableName; string sets = this.Context.Runtime.SqlGenerator.GenerateSetSegments <T>(fieldsToUpdate, segment.Parameters); string where = this.Context.Runtime.SqlGenerator.GenerateFilter <T>(filter, segment.Parameters); if (string.IsNullOrWhiteSpace(where)) { throw new NotSupportedException("不支持没有where条件的UPDATE语句"); } segment.Sql = $"UPDATE {this.Context.Runtime.DelimitIdentifier(typeof(T), tableName)} SET {sets} WHERE {where}"; return(segment); }