标签:
整理了10个ORM框架测试示例,排名不分先后
上面的框架里,风格不一,多数为半对象化,需要以参数形式传值,效率可能高点,但编程性和便捷性就会差点
目的
测试结果
为了体现ORM过程,尽量使用对象来表示
实体接口
public interface IProduct
{
int Id { get; set; }
string ProductId { get; set; }
string ProductName { get; set; }
string BarCode { get; set; }
DateTime AddTime { get; set; }
}
测试接口
public interface ITester
{
IProduct GetProduct(int index);
string Remark { get; }
bool Insert(int index);
int Select(int index);
int Update(int index);
int Delete(int index);
}
接口实现示例
public class CRLTester : ITester
{
public string Remark
{
get
{
return "";
}
}
public IProduct GetProduct(int index)
{
return new Product() { Id = index, ProductName = "ProductName" + index, BarCode = "BarCode" + index, AddTime = DateTime.Now };
}
public bool Insert(int index)
{
var data = GetProduct(index) as Product;
ProductManage.Instance.Add(data);
return true;
}
public int Select(int index)
{
var data = GetProduct(index) as Product;
var list = ProductManage.Instance.QueryList(b => b.ProductName == data.ProductName);
return list.Count;
}
public int Delete(int index)
{
var data = GetProduct(index) as Product;
var n = ProductManage.Instance.Delete(b => b.Id == data.Id);
return n;
}
public int Update(int index)
{
var data = GetProduct(index) as Product;
//因为不是查询出来的,手动设置哪些属性被更改了
data.Change(b => b.ProductName);
data.Change(b => b.BarCode);
return ProductManage.Instance.Update(data);
}
}
测试过程,调用接口实现,对增删改查循环执行指定次数
static string DoTest(ITester tester, TestType type,int n)
{
Stopwatch sw = new Stopwatch();
//插入
sw.Start();
for (int i = 1; i <= n; i++)
{
switch (type)
{
case TestType.DELETE:
tester.Delete(i);
break;
case TestType.INSERT:
tester.Insert(i);
break;
case TestType.SELECT:
tester.Select(i);
break;
case TestType.UPDATE:
tester.Update(i);
break;
}
}
sw.Stop();
var times = sw.ElapsedMilliseconds;
var avg = times / Convert.ToDouble(n);
return string.Format("{0},用时 {1} 毫秒 平均 {2}", type, sw.ElapsedMilliseconds, avg);
}
运行截图,没有使用本地数据库,数据没有参考性

项目下载地址:http://files.cnblogs.com/files/hubro/ORMTest.rar
请更改config文件中的数据连接,IBatisNet需单独修改
标签:
原文地址:http://www.cnblogs.com/hubro/p/4422068.html