mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Update Demo
This commit is contained in:
parent
8479b4ff33
commit
24bbffa2df
@ -1,6 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</configSections>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
|
||||
<parameters>
|
||||
<parameter value="mssqllocaldb" />
|
||||
</parameters>
|
||||
</defaultConnectionFactory>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
</providers>
|
||||
</entityFramework>
|
||||
</configuration>
|
@ -9,6 +9,7 @@ namespace PerformanceTest
|
||||
public enum OrmType
|
||||
{
|
||||
SqlSugar,
|
||||
Dapper
|
||||
Dapper,
|
||||
EF
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Data.Entity.ModelConfiguration.Conventions;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PerformanceTest
|
||||
{
|
||||
[Dapper.Contrib.Extensions.Table("Test")]
|
||||
@ -23,4 +24,16 @@ namespace PerformanceTest
|
||||
public Guid? F_Guid { get; set; }
|
||||
public string F_String { get; set; }
|
||||
}
|
||||
|
||||
public class EFContext : DbContext
|
||||
{
|
||||
public EFContext(string connectionString) : base(connectionString) {
|
||||
|
||||
}
|
||||
public DbSet<Test> TestList { get; set; }
|
||||
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Test>().ToTable("Test");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,10 +41,19 @@
|
||||
<HintPath>..\packages\Dapper.Contrib.1.50.0\lib\net45\Dapper.Contrib.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="SyntacticSugar">
|
||||
<HintPath>..\SqliteTest\OtherDll\SyntacticSugar.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.Linq" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
|
@ -15,8 +15,8 @@ namespace PerformanceTest
|
||||
/// <param name="args"></param>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//new TestGetAll().Init(OrmType.SqlSugar);
|
||||
// new TestGetById().Init(OrmType.SqlSugar);
|
||||
//new TestGetAll().Init(OrmType.Dapper);
|
||||
//new TestGetById().Init(OrmType.EF);
|
||||
new TestSql().Init(OrmType.SqlSugar);
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Data.SqlClient;
|
||||
using Dapper;
|
||||
using SqlSugar;
|
||||
using Dapper.Contrib.Extensions;
|
||||
using System.Data.Entity;
|
||||
|
||||
namespace PerformanceTest.TestItems
|
||||
{
|
||||
@ -13,6 +14,7 @@ namespace PerformanceTest.TestItems
|
||||
{
|
||||
public void Init(OrmType type)
|
||||
{
|
||||
Database.SetInitializer<EFContext>(null);
|
||||
Console.WriteLine("测试一次读取100万条数据的速度");
|
||||
var eachCount = 1;
|
||||
|
||||
@ -27,6 +29,9 @@ namespace PerformanceTest.TestItems
|
||||
case OrmType.Dapper:
|
||||
Dapper(eachCount);
|
||||
break;
|
||||
case OrmType.EF:
|
||||
EF(eachCount);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -63,5 +68,19 @@ namespace PerformanceTest.TestItems
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void EF(int eachCount)
|
||||
{
|
||||
GC.Collect();//回收资源
|
||||
System.Threading.Thread.Sleep(1);//休息1秒
|
||||
|
||||
PerHelper.Execute(eachCount, "EF", () =>
|
||||
{
|
||||
using (EFContext conn = new EFContext(Config.connectionString))
|
||||
{
|
||||
var list = conn.TestList.AsNoTracking().ToList();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -14,6 +15,7 @@ namespace PerformanceTest.TestItems
|
||||
|
||||
public void Init(OrmType type)
|
||||
{
|
||||
Database.SetInitializer<EFContext>(null);
|
||||
Console.WriteLine("测试一次读取1条数据的速度");
|
||||
var eachCount = 1000;
|
||||
|
||||
@ -28,6 +30,9 @@ namespace PerformanceTest.TestItems
|
||||
case OrmType.Dapper:
|
||||
Dapper(eachCount);
|
||||
break;
|
||||
case OrmType.EF:
|
||||
EF(eachCount);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -63,5 +68,20 @@ namespace PerformanceTest.TestItems
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static void EF(int eachCount)
|
||||
{
|
||||
GC.Collect();//回收资源
|
||||
System.Threading.Thread.Sleep(1);//休息1秒
|
||||
|
||||
PerHelper.Execute(eachCount, "EF", () =>
|
||||
{
|
||||
using (EFContext conn = new EFContext(Config.connectionString))
|
||||
{
|
||||
var list = conn.TestList.AsNoTracking().Single(it=>it.Id==1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -13,6 +14,7 @@ namespace PerformanceTest.TestItems
|
||||
{
|
||||
public void Init(OrmType type)
|
||||
{
|
||||
Database.SetInitializer<EFContext>(null);
|
||||
Console.WriteLine("测试SQL查询的速度");
|
||||
var eachCount = 3000;
|
||||
|
||||
@ -27,6 +29,9 @@ namespace PerformanceTest.TestItems
|
||||
case OrmType.Dapper:
|
||||
Dapper(eachCount);
|
||||
break;
|
||||
case OrmType.EF:
|
||||
EF(eachCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Console.Write("总计:" + (DateTime.Now - beginDate).TotalMilliseconds / 1000.0);
|
||||
@ -59,5 +64,19 @@ namespace PerformanceTest.TestItems
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void EF(int eachCount)
|
||||
{
|
||||
GC.Collect();//回收资源
|
||||
System.Threading.Thread.Sleep(1);//休息1秒
|
||||
|
||||
PerHelper.Execute(eachCount, "EF", () =>
|
||||
{
|
||||
using (EFContext conn = new EFContext(Config.connectionString))
|
||||
{
|
||||
var list = conn.Database.SqlQuery<Test>("select top 10 * from Test").ToList();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user