/// <summary> /// 执行SQL 语句,并返回 <see cref="IEnumerable"/> 对象 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="query">SQL 命令</param> /// <returns></returns> public List <T> ExecuteList <T>(IDbQueryable <T> query) { DbCommandDefinition definition = query.Resolve(); IDbCommand cmd = this.CreateCommand(definition); return(this.ExecuteList <T>(cmd, definition as DbCommandDefinition_Select)); }
/// <summary> /// 执行SQL 语句,并返回 <see cref="DataTable"/> 对象 /// </summary> /// <param name="query">SQL 命令</param> /// <returns></returns> public DataTable ExecuteDataTable(IDbQueryable query) { DbCommandDefinition definition = query.Resolve(); IDbCommand cmd = this.CreateCommand(definition); return(this.ExecuteDataTable(cmd)); }
// 解析批量 INSERT 语句 protected void ResolveBulk(List <DbCommandDefinition> sqlList, List <IDbQueryable> bulkList) { // SQL 只能接收1000个 int pageSize = 1000; int pages = bulkList.Page(pageSize); for (int pageIndex = 1; pageIndex <= pages; pageIndex++) { var dbQueryables = bulkList.Skip((pageIndex - 1) * pageSize).Take(pageSize); int i = 0; int t = dbQueryables.Count(); var builder = new System.Text.StringBuilder(128); foreach (IDbQueryable query in dbQueryables) { i += 1; query.Parameterized = false; query.Bulk = new BulkInsertInfo { OnlyValue = i != 1, IsEndPos = i == t }; DbCommandDefinition cmd = query.Resolve(); builder.Append(cmd.CommandText); } if (builder.Length > 0) { sqlList.Add(new DbCommandDefinition(builder.ToString())); } } }
/// <summary> /// 执行SQL 语句,并返回 <see cref="DataTable"/> 对象 /// </summary> /// <param name="query">SQL 命令</param> /// <returns></returns> public async Task <DataTable> ExecuteDataTableAsync(IDbQueryable query) { DbCommandDefinition definition = query.Resolve(); IDbCommand cmd = this.CreateCommand(definition); return(await this.ExecuteDataTableAsync(cmd)); }
/// <summary> /// 异步执行SQL 语句,并返回 <see cref="IEnumerable"/> 对象 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="query">SQL 命令</param> /// <returns></returns> public async Task <List <T> > ExecuteListAsync <T>(IDbQueryable <T> query) { DbCommandDefinition definition = query.Resolve(); IDbCommand cmd = this.CreateCommand(definition.CommandText, definition.CommandType, definition.Parameters); return(await this.ExecuteListAsync <T>(cmd, definition as DbCommandDefinition_Select)); }
/// <summary> /// 异步执行SQL 语句,并返回单个实体对象 /// </summary> /// <param name="query">SQL 命令</param> /// <returns></returns> public async Task <T> ExecuteAsync <T>(IDbQueryable <T> query) { DbCommandDefinition definition = query.Resolve(); IDbCommand cmd = this.CreateCommand(definition); return(await this.ExecuteAsync <T>(cmd, definition as DbCommandDefinition_Select)); }
/// <summary> /// 创建 SQL 命令 /// </summary> /// <param name="definition">命令描述</param> /// <returns></returns> public IDbCommand CreateCommand(DbCommandDefinition definition) { return(this.CreateCommand(definition.CommandText, definition.CommandType, definition.Parameters)); }