SqlSugar源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.3 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
4 years ago
using PerformanceTest.Models;
7 years ago
using PerformanceTest.TestItems;
5 years ago
using SqlSugar;
namespace PerformanceTest
{
class Program
{
7 years ago
/// <summary>
7 years ago
/// 注意注意注意注意注意:分开测试比较公平,并且请在Realse模式下启动程序(SqlSugar直接引用的是项目)
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
4 years ago
InitData();
5 years ago
4 years ago
var type = DemoType.Like;
var ormType = OrmType.FREE;
7 years ago
switch (type)
{
case DemoType.GetAll:
new TestGetAll().Init(ormType);
break;
case DemoType.GetById:
7 years ago
new TestGetById().Init(ormType);
7 years ago
break;
7 years ago
case DemoType.GetSql:
new TestGetSql().Init(ormType);
7 years ago
break;
5 years ago
case DemoType.Insert:
new TestInsert().Init(ormType);
break;
4 years ago
case DemoType.Like:
new TestLike().Init(ormType);
break;
4 years ago
case DemoType.OnToN:
new TestOneToMany().Init(ormType);
break;
7 years ago
default:
break;
}
Console.ReadKey();
}
5 years ago
private static void InitData()
{
SqlSugarClient conn = Config.GetSugarConn();
conn.CurrentConnectionConfig.InitKeyType = InitKeyType.Attribute;
conn.DbMaintenance.CreateDatabase();//创建库
conn.CodeFirst.InitTables<Test>();
List<Test> test = new List<Test>();
if (conn.Queryable<Test>().Count() < 100000)
{
Console.WriteLine("初始化数据");
for (int i = 0; i < 100000; i++)
{
test.Add(new Test()
{
F_Bool = true,
F_Byte = 0,
F_DateTime = DateTime.Now,
F_Decimal = 1,
F_Double = 11,
F_Float = 11,
F_Guid = Guid.Empty,
F_String = "abc",
F_Int16 = 1,
F_Int32 = 1,
F_Int64 = 1
});
}
}
4 years ago
conn.CodeFirst.InitTables<Group>();
conn.DbMaintenance.TruncateTable<Group>();
conn.CodeFirst.InitTables<User>();
conn.DbMaintenance.TruncateTable<User>();
//for (int i = 0; i < 1000; i++)
//{
// conn.Insertable(new Group { Id=i,Name=i+Guid.NewGuid().ToString() }).ExecuteCommand();
// conn.Insertable(new User() { AGroupId = i, Id = i + 1 }).ExecuteCommand();
// conn.Insertable(new User() { AGroupId = i, Id = i + 200000 }).ExecuteCommand();
//}
5 years ago
conn.Insertable(test).ExecuteCommand();
}
7 years ago
enum DemoType
{
GetAll,
GetById,
5 years ago
GetSql,
4 years ago
Insert,
4 years ago
Like,
OnToN
7 years ago
}
}
}