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>
|
<configuration>
|
||||||
<startup>
|
<configSections>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||||
</startup>
|
<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>
|
</configuration>
|
@ -9,6 +9,7 @@ namespace PerformanceTest
|
|||||||
public enum OrmType
|
public enum OrmType
|
||||||
{
|
{
|
||||||
SqlSugar,
|
SqlSugar,
|
||||||
Dapper
|
Dapper,
|
||||||
|
EF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Entity;
|
||||||
|
using System.Data.Entity.ModelConfiguration.Conventions;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace PerformanceTest
|
namespace PerformanceTest
|
||||||
{
|
{
|
||||||
[Dapper.Contrib.Extensions.Table("Test")]
|
[Dapper.Contrib.Extensions.Table("Test")]
|
||||||
@ -23,4 +24,16 @@ namespace PerformanceTest
|
|||||||
public Guid? F_Guid { get; set; }
|
public Guid? F_Guid { get; set; }
|
||||||
public string F_String { 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>
|
<HintPath>..\packages\Dapper.Contrib.1.50.0\lib\net45\Dapper.Contrib.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</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">
|
<Reference Include="SyntacticSugar">
|
||||||
<HintPath>..\SqliteTest\OtherDll\SyntacticSugar.dll</HintPath>
|
<HintPath>..\SqliteTest\OtherDll\SyntacticSugar.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Data.Linq" />
|
<Reference Include="System.Data.Linq" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
@ -15,8 +15,8 @@ namespace PerformanceTest
|
|||||||
/// <param name="args"></param>
|
/// <param name="args"></param>
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
//new TestGetAll().Init(OrmType.SqlSugar);
|
//new TestGetAll().Init(OrmType.Dapper);
|
||||||
// new TestGetById().Init(OrmType.SqlSugar);
|
//new TestGetById().Init(OrmType.EF);
|
||||||
new TestSql().Init(OrmType.SqlSugar);
|
new TestSql().Init(OrmType.SqlSugar);
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ using System.Data.SqlClient;
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Dapper.Contrib.Extensions;
|
using Dapper.Contrib.Extensions;
|
||||||
|
using System.Data.Entity;
|
||||||
|
|
||||||
namespace PerformanceTest.TestItems
|
namespace PerformanceTest.TestItems
|
||||||
{
|
{
|
||||||
@ -13,6 +14,7 @@ namespace PerformanceTest.TestItems
|
|||||||
{
|
{
|
||||||
public void Init(OrmType type)
|
public void Init(OrmType type)
|
||||||
{
|
{
|
||||||
|
Database.SetInitializer<EFContext>(null);
|
||||||
Console.WriteLine("测试一次读取100万条数据的速度");
|
Console.WriteLine("测试一次读取100万条数据的速度");
|
||||||
var eachCount = 1;
|
var eachCount = 1;
|
||||||
|
|
||||||
@ -27,6 +29,9 @@ namespace PerformanceTest.TestItems
|
|||||||
case OrmType.Dapper:
|
case OrmType.Dapper:
|
||||||
Dapper(eachCount);
|
Dapper(eachCount);
|
||||||
break;
|
break;
|
||||||
|
case OrmType.EF:
|
||||||
|
EF(eachCount);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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 SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Entity;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -14,6 +15,7 @@ namespace PerformanceTest.TestItems
|
|||||||
|
|
||||||
public void Init(OrmType type)
|
public void Init(OrmType type)
|
||||||
{
|
{
|
||||||
|
Database.SetInitializer<EFContext>(null);
|
||||||
Console.WriteLine("测试一次读取1条数据的速度");
|
Console.WriteLine("测试一次读取1条数据的速度");
|
||||||
var eachCount = 1000;
|
var eachCount = 1000;
|
||||||
|
|
||||||
@ -28,6 +30,9 @@ namespace PerformanceTest.TestItems
|
|||||||
case OrmType.Dapper:
|
case OrmType.Dapper:
|
||||||
Dapper(eachCount);
|
Dapper(eachCount);
|
||||||
break;
|
break;
|
||||||
|
case OrmType.EF:
|
||||||
|
EF(eachCount);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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 SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Entity;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -13,6 +14,7 @@ namespace PerformanceTest.TestItems
|
|||||||
{
|
{
|
||||||
public void Init(OrmType type)
|
public void Init(OrmType type)
|
||||||
{
|
{
|
||||||
|
Database.SetInitializer<EFContext>(null);
|
||||||
Console.WriteLine("测试SQL查询的速度");
|
Console.WriteLine("测试SQL查询的速度");
|
||||||
var eachCount = 3000;
|
var eachCount = 3000;
|
||||||
|
|
||||||
@ -27,6 +29,9 @@ namespace PerformanceTest.TestItems
|
|||||||
case OrmType.Dapper:
|
case OrmType.Dapper:
|
||||||
Dapper(eachCount);
|
Dapper(eachCount);
|
||||||
break;
|
break;
|
||||||
|
case OrmType.EF:
|
||||||
|
EF(eachCount);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Console.Write("总计:" + (DateTime.Now - beginDate).TotalMilliseconds / 1000.0);
|
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