private void QueryAsync() { var dapperInstance = _dapper; var id = helper.GetValue("SELECT ifnull((SELECT MAX(products_id) FROM test.dapper_compisite_key),0)", Convert.ToInt32); var insertId = helper.GetValue($"INSERT INTO test.dapper_compisite_key VALUES ({++id},{id}, '{id.ToString()}', '{id.ToString()}', '{id.ToString()}', '{id.ToString()}', 2); SELECT MAX(products_id) FROM dapper_compisite_key dck;select {id};", Convert.ToInt32); SingleQueryFilter filter = new SingleQueryFilter().AddEqual("products_id", insertId); var result = dapperInstance.QueryAsync(filter).GetAwaiter().GetResult() ?? new List <DapperCompisiteKeyEntity>(); helper.ExecuteReader($"select * from dapper_compisite_key where products_id={insertId}", reader => { while (reader.Read()) { CompareHelper.Compare(reader, result.Where(x => x.products_id == Convert.ToInt32(reader["products_id"] ?? 0)).FirstOrDefault()); } }); helper.ExecuteSQL($"delete from test.dapper_compisite_key where products_id = {insertId}", cmd => cmd.ExecuteNonQuery(), false); }
public void UpdateSync() { ClearDapperTestEntity(); var d1 = CreateDapperTestEntity(); try { #region 实体对象赋值 d1.id = 22; d1.bigint_value = 2; d1.datetime_value = new DateTime(1988, 11, 12, 17, 34, 21); d1.date_value = new DateTime(1988, 11, 12); d1.decimal_value = 100m; d1.dec_value = 20.3m; d1.double_value = 300d; d1.fix_value = 500.5m; d1.float_value = 600.6f; d1.integer_value = 76543; d1.int_value = 888; d1.mediumint_value = 999; d1.numeric_value = 10101; d1.real_value = 12312; d1.smallint_value = 23; d1.tinyint_value = 11; d1.longtext_null_value = "codemonk"; #endregion _dapper.UpdateAsync(d1).GetAwaiter().GetResult(); var sql = $@"select * from ""dapper_all_test"" where ""id""={d1.id}"; SQLiteHelper.ExecuteReader(sql, reader => { while (reader.Read()) { CompareHelper.Compare(reader, d1); } }); } finally { ClearDapperTestEntity(); } }
private void QueryLess() { ClearDapperCompisiteKeyEntity(); var d1 = CreateDapperCompisiteKeyEntity(); var d2 = CreateDapperCompisiteKeyEntity(2, 2); var d3 = CreateDapperCompisiteKeyEntity(3, 3); try { var dapperInstance = _dapper; SingleQueryFilter filter = new SingleQueryFilter().AddLess("products_id", 2); var dapperQueryResult = dapperInstance.Query(filter); CompareHelper.Compare(d1, dapperQueryResult.Where(s => s.products_id == 1).FirstOrDefault()); Assert.Equal(1, dapperQueryResult.Count()); } finally { ClearDapperCompisiteKeyEntity(); } }
private void QueryFirstOrDefaultAsync() { ClearDapperTestEntity(); var d1 = CreateDapperTestEntity(); try { var filter = new SingleQueryFilter().AddEqual("id", d1.id); var result = _dapper.QueryFirstOrDefaultAsync(filter).GetAwaiter().GetResult(); var sql = string.Format("select * from dapper_all_test where id={0}", d1.id); helper.ExecuteReader(sql, reader => { if (reader.Read()) { CompareHelper.Compare(reader, result); } }); } finally { ClearDapperTestEntity(); } }
public void UpdateSync() { ClearDapperCompisiteKeyEntity(); var d1 = CreateDapperCompisiteKeyEntity(); try { d1.products_name = "testtest"; _dapper.UpdateAsync(d1).GetAwaiter().GetResult(); var sql = $"select * from dapper_compisite_key where products_id = {d1.products_id} and language_id = {d1.language_id}"; helper.ExecuteReader(sql, reader => { while (reader.Read()) { CompareHelper.Compare(reader, d1); } }); } finally { ClearDapperCompisiteKeyEntity(); } }
private void QueryAllAsync() { ClearDapperTestEntity(); CreateDapperTestEntity(); CreateDapperTestEntity(2); CreateDapperTestEntity(3); try { var result = _dapper.QueryAllAsync().GetAwaiter().GetResult() ?? new List <SQLiteDapperTestEntity>(); var sql = @"select * from ""dapper_all_test"""; SQLiteHelper.ExecuteReader(sql, reader => { while (reader.Read()) { CompareHelper.Compare(reader, result.FirstOrDefault(x => x.id == Convert.ToInt32(reader["id"]))); } }); } finally { ClearDapperTestEntity(); } }
private void QueryAllAsync() { ClearTestEntity(); var d1 = CreateTestEntity(); var d2 = CreateTestEntity(2); var d3 = CreateTestEntity(3); try { var dapperInstance = _dapper; var result = dapperInstance.QueryAllAsync().GetAwaiter().GetResult(); helper.ExecuteReader("select * from DapperAllTest", reader => { while (reader.Read()) { CompareHelper.ComparePascalCase(reader, result.Where(x => x.Id == Convert.ToInt32(reader["id"] ?? 0)).FirstOrDefault()); } }); } finally { ClearTestEntity(); } }
private void QueryFirstOrDefault() { ClearTestEntity(); var d1 = CreateTestEntity(); try { var dapperInstance = _dapper; var filter = new SingleQueryFilter().AddEqual("id", d1.Id); var result = dapperInstance.QueryFirstOrDefault(filter); var sql = string.Format("select * from DapperAllTest where id={0}", d1.Id); helper.ExecuteReader(sql, reader => { if (reader.Read()) { CompareHelper.ComparePascalCase(reader, result); } }); } finally { ClearTestEntity(); } }
private void QueryAll() { ClearDapperTestEntity(); var d1 = CreateDapperTestEntity(); var d2 = CreateDapperTestEntity(2); var d3 = CreateDapperTestEntity(3); try { var result = _dapper.QueryAll() ?? new List <DapperTestEntity>(); var sql = "select * from dapper_all_test"; helper.ExecuteReader(sql, reader => { while (reader.Read()) { CompareHelper.Compare(reader, result.Where(x => x.id == Convert.ToInt32(reader["id"])).FirstOrDefault()); } }); } finally { ClearDapperTestEntity(); } }
private void QueryAsync() { ClearDapperTestEntity(); CreateDapperTestEntity(); CreateDapperTestEntity(2); CreateDapperTestEntity(3); try { var dapperInstance = _dapper; var filter = new SingleQueryFilter().AddEqual(nameof(DapperEntityWithNoBool.dec_value), 200m); var result = dapperInstance.QueryAsync(filter).GetAwaiter().GetResult(); SQLiteHelper.ExecuteReader(@"select * from ""dapper_all_test"" where ""id""=1", reader => { while (reader.Read()) { CompareHelper.Compare(reader, result.FirstOrDefault(x => x.id == Convert.ToInt32(reader["id"]))); } }); } finally { ClearDapperTestEntity(); } }
private void QueryFirstOrDefault() { ClearDapperTestEntity(); var d1 = CreateDapperTestEntity(); try { var dapperInstance = _dapper; var filter = new SingleQueryFilter().AddEqual("id", d1.id); var result = dapperInstance.QueryFirstOrDefault(filter); var sql = $@"select * from ""dapper_all_test"" where ""id""={d1.id}"; SQLiteHelper.ExecuteReader(sql, reader => { if (reader.Read()) { CompareHelper.Compare(reader, result); } }); } finally { ClearDapperTestEntity(); } }