CSFramework.EF 数据库框架 - 测试异步方法 (Async)
C# 全选
private void button2_Click(object sender, EventArgs e)
{
//
//测试异步方法,www.csframework.com
//
var config = GetConfig("WebApiSystem");
IDatabase db = DatabaseFactory.GetDatabase(config);
_NewCustomers.Clear();
//测试异步
Task.Run(() =>
{
DoTestAsync(db);
}).Wait();
}
C# 全选
private async Task<String> DoTestAsync(IDatabase db)
{
var result = "";
_NewCustomers.Clear();
result += await db.AddAsync<Test_Customer>(NewCustomer());
result += await db.AddAsync<Test_Customer>(NewCustomer());
result += await db.AddAsync<Test_Customer>(NewCustomerList());
result += await db.AddAsync<Test_Customer>(NewCustomerList());
result += await db.ExecuteSqlAsync("select 1 from Test_Customer;");
result += await db.RemoveAsync<Test_Customer>(_NewCustomers[0]);
result += await db.RemoveAsync<Test_Customer>(new List<Test_Customer> { _NewCustomers[1], _NewCustomers[2] });
var obj = _NewCustomers[3];
obj.NativeName = "Async修改了:" + obj.NativeName;
result += db.UpdateAsync<Test_Customer>(obj).Result;
await db.RunTransactionAsync(() =>
{
//edit
obj = _NewCustomers[4];
obj.NativeName = "RunTransactionAsync修改了:" + obj.NativeName;
result += db.Update<Test_Customer>(obj);
//remove
result += db.Remove(_NewCustomers[5]);
result += db.Add<Test_Customer>(NewCustomer());
return Task.CompletedTask;
});
//获取本次Test的对象
var isid = _NewCustomers.Select(s => s.isid).ToList();
var listResult = db.GetQueryable<Test_Customer>().Where(w => isid.Contains(w.isid)).ToList();
this.Invoke(new OnShowGridAsync(this.ShowGrid), listResult, result);
return result;
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
CSFramework.EF C/S框架网