public async Task UpdateAsync(Expression <Func <T> > update, Expression <Func <T, bool> > condition) { var updateSql = new SQLinqUpdate <T>(this.SqlDialect); updateSql.Where(condition); updateSql.UpdateSet(update); var queryRst = updateSql.ToSQL(); this.Logger.LogDebug($"SQL:{queryRst.ToQuery()}{Environment.NewLine}Params:{queryRst.Parameters}"); await this.Connection.ExecuteAsync(queryRst.ToQuery(), queryRst.Parameters); }
public void UpdateSetExpression_test() { var sqlinq = new SQLinqUpdate <ToSQL_009_Class>(new MySqlDialect()); sqlinq.UpdateSet(() => new ToSQL_009_Class() { ID = 1, Name = "test" }); var sql = sqlinq.ToSQL(); }
public async Task ChangeAppSecuretAsync(long id, string newSecuret) { var app = await base.QueryFirstAsync(x => x.Id == id); var sqlGenerator = new SQLinq <UserEntity>(base.SqlDialect); var updateSql = new SQLinqUpdate <UserEntity>(this.SqlDialect); updateSql.Where(x => x.Id == app.AppUserId); updateSql.UpdateSet(() => new UserEntity { Password = newSecuret }); var sqlResult = updateSql.ToSQL(); var sql = sqlResult.ToQuery(); var paramaters = sqlResult.Parameters; await this.Connection.ExecuteAsync(sql, paramaters); }
public async Task ChangeAppSecuretAsync(ApplicationEntity entity) { var sqlGenerator = new SQLinq <UserEntity>(base.SqlDialect); sqlGenerator.Where(x => x.Id == entity.AppUserId); var sqlResult = sqlGenerator.ToSQL(); var sql = sqlResult.ToQuery(); var updateSqlGenerator = new SQLinqUpdate <UserEntity>(base.SqlDialect); updateSqlGenerator.Where(x => x.Id == entity.AppUserId); updateSqlGenerator.UpdateSet(() => new UserEntity { Password = entity.Account.Password, Salt = entity.Account.Salt }); var updateSqlResult = updateSqlGenerator.ToSQL(); var updateSql = updateSqlResult.ToQuery(); await this.Connection.ExecuteAsync(updateSql, updateSqlResult.Parameters); }
public void UpdateSetExpression_test() { var sqlinq = new SQLinqUpdate <ToSQL_009_Class>(new MySqlDialect()); sqlinq.UpdateSet(() => new ToSQL_009_Class() { ID = 1, //Name = "test" }); sqlinq.Where(x => x.ID == 1024); var sql = sqlinq.ToSQL(); var query = sql.ToQuery(); var sqlResult = "UPDATE `MyTable` SET `ID` = @sqlinq_2\r\n WHERE `ID` = @sqlinq_1"; Assert.AreEqual(sqlResult, query); Assert.AreEqual(sql.Parameters.Count, 2); Assert.AreEqual(sql.Parameters["@sqlinq_2"], 1); Assert.AreEqual(sql.Parameters["@sqlinq_1"], 1024); }