/// <summary> /// Perform update table with data from an anonymous object /// </summary> /// <typeparam name="T"></typeparam> /// <param name="db"></param> /// <param name="columns">Select which columns to update from an anonymous object</param> /// <param name="cfg">Configure name and other</param> /// <returns></returns> public static IBuildUpdateTableFrom <T> UpdateFrom <T>(this DbConnection db, Func <IUpdateColumns, IColumnsToUpdate <T> > columns, Action <IHelperOptions> cfg) where T : class { var options = new HelperOptions(); var u = new UpdateColumns(); cfg(options); options.EnsureTableName(db.GetPocoInfo <T>()); var builder = columns(u) as UpdateColumns.CreateBuilder <T>; var executor = new CustomSqlExecutor(db); var updater = new UpdateTableBuilder <T>(executor, db.GetExpressionSqlGenerator(), db.Provider(), options); builder.PopulateBuilder(updater); return(updater); }
/// <summary> /// Perform update table with data from an anonymous object /// </summary> /// <typeparam name="T"></typeparam> /// <param name="db"></param> /// <param name="valuesToUpdate"></param> /// <param name="tableName"></param> /// <returns></returns> public static IBuildAnonymousUpdate UpdateFrom <T>(this DbConnection db, T valuesToUpdate, TableName tableName) where T : class { tableName.MustNotBeNull(); var options = new HelperOptions(db.GetPocoInfo <T>()); options.TableName = tableName; var executor = new CustomSqlExecutor(db); var updater = new UpdateTableBuilder <T>(executor, db.GetExpressionSqlGenerator(), db.Provider(), options); updater.SetUpdates(valuesToUpdate); return(new UpdateAnonymousBuilder <T>(updater)); }