public static Task <int> UpdateAsync <T>(this IDbConnection connection, T data, Expression <Func <T, bool> > predicate, bool setIdentity, params Expression <Func <T, object> >[] properties) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } if (data == null) { throw new ArgumentNullException(nameof(data)); } if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } if (properties == null) { throw new ArgumentNullException(nameof(properties)); } var dbKind = connection.GetDbKind(); var update = PrimitiveSql.CreateUpdate(dbKind, setIdentity, properties); var where = PredicateSql.From(dbKind, predicate); var param = where.Parameter.Merge(data, properties); var builder = new StringBuilder(); builder.AppendLine(update); builder.AppendLine(nameof(where)); builder.Append($" {where.Statement}"); return(connection.ExecuteAsync(builder.ToString(), param)); }
/// <summary> /// 指定の条件に一致するレコードを指定された情報で非同期的に更新します。 /// </summary> /// <typeparam name="T">テーブルの型</typeparam> /// <param name="data">更新するデータ</param> /// <param name="predicate">更新条件</param> /// <param name="properties">更新する列にマッピングされるプロパティ式のコレクション</param> /// <param name="setIdentity">自動採番のID列に値を設定するかどうか</param> /// <returns>影響した行数</returns> public virtual Task <int> UpdateAsync <T>(T data, Expression <Func <T, bool> > predicate, Expression <Func <T, object> > properties, bool setIdentity) { var update = PrimitiveSql.CreateUpdate(this.DbKind, properties, setIdentity); var where = PredicateSql.From(this.DbKind, predicate); var param = where.Parameter.Merge(data, properties); var builder = new StringBuilder(); builder.AppendLine(update); builder.AppendLine(nameof(where)); builder.Append($" {where.Statement}"); return(this.Connection.ExecuteAsync(builder.ToString(), param, this.Transaction, this.Timeout)); }
public void 特定1列のUpdate文生成() { var actual1 = PrimitiveSql.CreateUpdate(DbKind.SqlServer, typeof(Person), new [] { "Name" }); var actual2 = PrimitiveSql.CreateUpdate <Person>(DbKind.SqlServer, x => x.Name); var actual3 = PrimitiveSql.CreateUpdate <Person>(DbKind.SqlServer, x => new { x.Name }); var expect = @"update dbo.Person set 名前 = @Name"; actual1.Is(expect); actual2.Is(expect); actual3.Is(expect); }
public void 全列のUpdate文生成() { var actual1 = PrimitiveSql.CreateUpdate(DbKind.SqlServer, typeof(Person)); var actual2 = PrimitiveSql.CreateUpdate <Person>(DbKind.SqlServer); var expect = @"update dbo.Person set 名前 = @Name, Age = @Age, HasChildren = @HasChildren"; actual1.Is(expect); actual2.Is(expect); }
public void IDを設定するUpdate文生成() { var actual1 = PrimitiveSql.CreateUpdate(DbKind.SqlServer, typeof(Person), setIdentity: true); var actual2 = PrimitiveSql.CreateUpdate <Person>(DbKind.SqlServer, setIdentity: true); var expect = @"update dbo.Person set Id = @Id, 名前 = @Name, Age = @Age, HasChildren = @HasChildren"; actual1.Is(expect); actual2.Is(expect); }
public static Task <int> UpdateAsync <T>(this IDbConnection connection, T data, bool setIdentity, params Expression <Func <T, object> >[] properties) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } if (data == null) { throw new ArgumentNullException(nameof(data)); } if (properties == null) { throw new ArgumentNullException(nameof(properties)); } var sql = PrimitiveSql.CreateUpdate(connection.GetDbKind(), setIdentity, properties); return(connection.ExecuteAsync(sql, data)); }
/// <summary> /// 指定された情報でレコードを非同期的に更新します。 /// </summary> /// <typeparam name="T">テーブルの型</typeparam> /// <param name="data">更新するデータ</param> /// <param name="properties">更新する列にマッピングされるプロパティ式のコレクション</param> /// <param name="setIdentity">自動採番のID列に値を設定するかどうか</param> /// <returns>影響した行数</returns> public virtual Task <int> UpdateAsync <T>(T data, Expression <Func <T, object> > properties, bool setIdentity) { var sql = PrimitiveSql.CreateUpdate(this.DbKind, properties, setIdentity); return(this.Connection.ExecuteAsync(sql, data, this.Transaction, this.Timeout)); }