CSFramework.EF 数据库框架 - 测试同步方法
C# 全选
//
//测试同步方法,www.csframework.com
//
var config = GetConfig("WebApiSystem");
IDatabase db = DatabaseFactory.GetDatabase(config);
var config1 = GetConfig("WebApiLog");
IDatabase dbLog = DatabaseFactory.GetDatabase(config1);
var q = db.GetQueryable<Test_Customer>();
var listCustomer = q.Take(10).ToList();
var q1 = dbLog.GetQueryable<sys_Log_ApiVistior>();
var list1 = q1.Take(10).ToList();
var result = "";
_NewCustomers.Clear();
result += db.Add<Test_Customer>(NewCustomer());
result += db.Add<Test_Customer>(NewCustomerList());
result += db.BulkInsert<Test_Customer>(NewCustomerList(100));
result += db.ExecuteSql("select 1 from Test_Customer;");
result += db.Remove<Test_Customer>(listCustomer[0]);
result += db.Remove<Test_Customer>(new List<Test_Customer> { listCustomer[1], listCustomer[2] });
var obj = listCustomer[3];
obj.NativeName = "修改了:" + obj.NativeName;
result += db.Update<Test_Customer>(obj);
obj = listCustomer[4];
obj.EnglishName = "修改了:" + obj.NativeName;
result += db.Update<Test_Customer>(obj);
db.RunTransaction(() =>
{
//edit
obj = listCustomer[4];
obj.NativeName = "RunTransaction修改了:" + obj.NativeName;
result += db.Update<Test_Customer>(obj);
//remove
result += db.Remove(listCustomer[5]);
result += db.Add<Test_Customer>(NewCustomer());
});
try
{
db.BeginTransaction(System.Data.IsolationLevel.Serializable);
//edit
obj = listCustomer[6];
obj.NativeName = "BeginTransaction修改了:" + obj.NativeName;
result += db.Update<Test_Customer>(obj);
//remove
result += db.Remove(listCustomer[7]);
result += db.Add<Test_Customer>(NewCustomer());
db.CommitTransaction();
}
catch
{
db.RollbackTransaction();
}
//获取本次Test的对象
var isid = listCustomer.Take(10).Union(_NewCustomers).Select(s => s.isid).ToList();
var listResult = db.GetQueryable<Test_Customer>().Where(w => isid.Contains(w.isid)).ToList();
ShowGrid(listResult);
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
CSFramework.EF C/S框架网