public void ToSQL_001() { var data = new Person { FirstName = "Chris", LastName = "Pietschmann" }; var target = new SQLinqUpdate<Person>(data); var actual = (SQLinqUpdateResult)target.ToSQL(); Assert.AreEqual("[Person]", actual.Table); Assert.AreEqual(7, actual.Fields.Count); Assert.AreEqual("@sqlinq_1", actual.Fields["ID"]); Assert.AreEqual("@sqlinq_2", actual.Fields["FirstName"]); Assert.AreEqual("@sqlinq_3", actual.Fields["LastName"]); Assert.AreEqual("@sqlinq_4", actual.Fields["Age"]); Assert.AreEqual("@sqlinq_5", actual.Fields["[Is_Employed]"]); Assert.AreEqual("@sqlinq_6", actual.Fields["ParentID"]); Assert.AreEqual("@sqlinq_7", actual.Fields["Column With Spaces"]); Assert.AreEqual(7, actual.Parameters.Count); Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_1"]); Assert.AreEqual("Chris", actual.Parameters["@sqlinq_2"]); Assert.AreEqual("Pietschmann", actual.Parameters["@sqlinq_3"]); Assert.AreEqual(0, actual.Parameters["@sqlinq_4"]); Assert.AreEqual(false, actual.Parameters["@sqlinq_5"]); Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_6"]); Assert.AreEqual(null, actual.Parameters["@sqlinq_7"]); }
public void ToSQL_001() { var data = new Person { FirstName = "Chris", LastName = "Pietschmann" }; var target = new SQLinqUpdate <Person>(data); var actual = (SQLinqUpdateResult)target.ToSQL(); Assert.AreEqual("[Person]", actual.Table); Assert.AreEqual(7, actual.Fields.Count); Assert.AreEqual("@sqlinq_1", actual.Fields["ID"]); Assert.AreEqual("@sqlinq_2", actual.Fields["FirstName"]); Assert.AreEqual("@sqlinq_3", actual.Fields["LastName"]); Assert.AreEqual("@sqlinq_4", actual.Fields["Age"]); Assert.AreEqual("@sqlinq_5", actual.Fields["[Is_Employed]"]); Assert.AreEqual("@sqlinq_6", actual.Fields["ParentID"]); Assert.AreEqual("@sqlinq_7", actual.Fields["Column With Spaces"]); Assert.AreEqual(7, actual.Parameters.Count); Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_1"]); Assert.AreEqual("Chris", actual.Parameters["@sqlinq_2"]); Assert.AreEqual("Pietschmann", actual.Parameters["@sqlinq_3"]); Assert.AreEqual(0, actual.Parameters["@sqlinq_4"]); Assert.AreEqual(false, actual.Parameters["@sqlinq_5"]); Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_6"]); Assert.AreEqual(null, actual.Parameters["@sqlinq_7"]); }
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); }
public void ToSQL_002() { var data = new PersonView { FirstName = "Chris", LastName = "Pietschmann" }; var target = new SQLinqUpdate<PersonView>(data); var actual = (SQLinqUpdateResult)target.ToSQL(); Assert.AreEqual("[vw_Person]", actual.Table); Assert.AreEqual(4, actual.Fields.Count); Assert.AreEqual("@sqlinq_1", actual.Fields["ID"]); Assert.AreEqual("@sqlinq_2", actual.Fields["First_Name"]); Assert.AreEqual("@sqlinq_3", actual.Fields["Last_Name"]); Assert.AreEqual("@sqlinq_4", actual.Fields["Age"]); Assert.AreEqual(4, actual.Parameters.Count); Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_1"]); Assert.AreEqual("Chris", actual.Parameters["@sqlinq_2"]); Assert.AreEqual("Pietschmann", actual.Parameters["@sqlinq_3"]); Assert.AreEqual(0, actual.Parameters["@sqlinq_4"]); }
public void ToSQL_002() { var data = new PersonView { FirstName = "Chris", LastName = "Pietschmann" }; var target = new SQLinqUpdate <PersonView>(data); var actual = (SQLinqUpdateResult)target.ToSQL(); Assert.AreEqual("[vw_Person]", actual.Table); Assert.AreEqual(4, actual.Fields.Count); Assert.AreEqual("@sqlinq_1", actual.Fields["ID"]); Assert.AreEqual("@sqlinq_2", actual.Fields["First_Name"]); Assert.AreEqual("@sqlinq_3", actual.Fields["Last_Name"]); Assert.AreEqual("@sqlinq_4", actual.Fields["Age"]); Assert.AreEqual(4, actual.Parameters.Count); Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_1"]); Assert.AreEqual("Chris", actual.Parameters["@sqlinq_2"]); Assert.AreEqual("Pietschmann", actual.Parameters["@sqlinq_3"]); Assert.AreEqual(0, actual.Parameters["@sqlinq_4"]); }