Skip to content

Commit de8cf9e

Browse files
2881028810
authored andcommitted
- 增加 .Net Framework 4.0 的支持,出于环境考虑 .Net Framework 4.0 不支持异步方法;
- 增加 IFreeSql.Insert<T>(IEnumerable<T1> source) 方法;
1 parent cb3e3b0 commit de8cf9e

File tree

139 files changed

+2752
-1822
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+2752
-1822
lines changed

Examples/orm_vs_net40/Program.cs

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
//using SqlSugar;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Diagnostics;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace orm_vs
11+
{
12+
class Program
13+
{
14+
static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
15+
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=20")
16+
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=20")
17+
.UseAutoSyncStructure(false)
18+
.UseNoneCommandParameter(true)
19+
//.UseConfigEntityFromDbFirst(true)
20+
.Build();
21+
22+
//static SqlSugarClient sugar
23+
//{
24+
// get => new SqlSugarClient(new ConnectionConfig()
25+
// {
26+
// //不欺负,让连接池100个最小
27+
// //ConnectionString = "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Min Pool Size=20;Max Pool Size=20",
28+
// //DbType = DbType.SqlServer,
29+
// ConnectionString = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Min Pool Size=20;Max Pool Size=20",
30+
// DbType = DbType.MySql,
31+
// IsAutoCloseConnection = true,
32+
// InitKeyType = InitKeyType.Attribute
33+
// });
34+
//}
35+
36+
static void Main(string[] args)
37+
{
38+
var testlist1 = fsql.Select<Song>().OrderBy(a => a.Id).ToList();
39+
var testlist2 = new List<Song>();
40+
fsql.Select<Song>().OrderBy(a => a.Id).ToChunk(0, list =>
41+
{
42+
testlist2.AddRange(list);
43+
});
44+
45+
fsql.CodeFirst.SyncStructure(typeof(Song), typeof(Song_tag), typeof(Tag));
46+
//sugar.CodeFirst.InitTables(typeof(Song), typeof(Song_tag), typeof(Tag));
47+
//sugar创建表失败:SqlSugar.SqlSugarException: Sequence contains no elements
48+
49+
//sugar.Aop.OnLogExecuted = (s, e) =>
50+
//{
51+
// Trace.WriteLine(s);
52+
//};
53+
//测试前清空数据
54+
fsql.Delete<Song>().Where(a => a.Id > 0).ExecuteAffrows();
55+
//sugar.Deleteable<Song>().Where(a => a.Id > 0).ExecuteCommand();
56+
fsql.Ado.ExecuteNonQuery("delete from efcore_song");
57+
58+
var sb = new StringBuilder();
59+
Console.WriteLine("插入性能:");
60+
Insert(sb, 1000, 1);
61+
Console.Write(sb.ToString());
62+
sb.Clear();
63+
Insert(sb, 1000, 10);
64+
Console.Write(sb.ToString());
65+
sb.Clear();
66+
67+
Insert(sb, 1, 1000);
68+
Console.Write(sb.ToString());
69+
sb.Clear();
70+
Insert(sb, 1, 10000);
71+
Console.Write(sb.ToString());
72+
sb.Clear();
73+
Insert(sb, 1, 50000);
74+
Console.Write(sb.ToString());
75+
sb.Clear();
76+
Insert(sb, 1, 100000);
77+
Console.Write(sb.ToString());
78+
sb.Clear();
79+
80+
Console.WriteLine("查询性能:");
81+
Select(sb, 1000, 1);
82+
Console.Write(sb.ToString());
83+
sb.Clear();
84+
Select(sb, 1000, 10);
85+
Console.Write(sb.ToString());
86+
sb.Clear();
87+
88+
Select(sb, 1, 1000);
89+
Console.Write(sb.ToString());
90+
sb.Clear();
91+
Select(sb, 1, 10000);
92+
Console.Write(sb.ToString());
93+
sb.Clear();
94+
Select(sb, 1, 50000);
95+
Console.Write(sb.ToString());
96+
sb.Clear();
97+
Select(sb, 1, 100000);
98+
Console.Write(sb.ToString());
99+
sb.Clear();
100+
101+
Console.WriteLine("更新:");
102+
Update(sb, 1000, 1);
103+
Console.Write(sb.ToString());
104+
sb.Clear();
105+
Update(sb, 1000, 10);
106+
Console.Write(sb.ToString());
107+
sb.Clear();
108+
109+
Update(sb, 1, 1000);
110+
Console.Write(sb.ToString());
111+
sb.Clear();
112+
Update(sb, 1, 10000);
113+
Console.Write(sb.ToString());
114+
sb.Clear();
115+
Update(sb, 1, 50000);
116+
Console.Write(sb.ToString());
117+
sb.Clear();
118+
Update(sb, 1, 100000);
119+
Console.Write(sb.ToString());
120+
sb.Clear();
121+
122+
Console.WriteLine("测试结束,按任意键退出...");
123+
Console.ReadKey();
124+
}
125+
126+
static void Select(StringBuilder sb, int forTime, int size)
127+
{
128+
Stopwatch sw = new Stopwatch();
129+
sw.Restart();
130+
for (var a = 0; a < forTime; a++)
131+
fsql.Select<Song>().Limit(size).ToList();
132+
sw.Stop();
133+
sb.AppendLine($"FreeSql Select {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");
134+
135+
//sw.Restart();
136+
//for (var a = 0; a < forTime; a++)
137+
// sugar.Queryable<Song>().Take(size).ToList();
138+
//sw.Stop();
139+
//sb.AppendLine($"SqlSugar Select {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");
140+
}
141+
142+
static void Insert(StringBuilder sb, int forTime, int size)
143+
{
144+
var songs = Enumerable.Range(0, size).Select(a => new Song
145+
{
146+
Create_time = DateTime.Now,
147+
Is_deleted = false,
148+
Title = $"Insert_{a}",
149+
Url = $"Url_{a}"
150+
});
151+
152+
//预热
153+
fsql.Insert(songs.First()).ExecuteAffrows();
154+
//sugar.Insertable(songs.First()).ExecuteCommand();
155+
Stopwatch sw = new Stopwatch();
156+
157+
sw.Restart();
158+
for (var a = 0; a < forTime; a++)
159+
{
160+
fsql.Insert(songs).ExecuteAffrows();
161+
//using (var db = new FreeSongContext()) {
162+
// //db.Configuration.AutoDetectChangesEnabled = false;
163+
// db.Songs.AddRange(songs.ToArray());
164+
// db.SaveChanges();
165+
//}
166+
}
167+
sw.Stop();
168+
sb.AppendLine($"FreeSql Insert {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");
169+
170+
//sw.Restart();
171+
//Exception sugarEx = null;
172+
//try
173+
//{
174+
// for (var a = 0; a < forTime; a++)
175+
// sugar.Insertable(songs.ToArray()).ExecuteCommand();
176+
//}
177+
//catch (Exception ex)
178+
//{
179+
// sugarEx = ex;
180+
//}
181+
//sw.Stop();
182+
//sb.AppendLine($"SqlSugar Insert {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms" + (sugarEx != null ? $"成绩无效,错误:{sugarEx.Message}" : ""));
183+
}
184+
185+
static void Update(StringBuilder sb, int forTime, int size)
186+
{
187+
Stopwatch sw = new Stopwatch();
188+
189+
var songs = fsql.Select<Song>().Limit(size).ToList();
190+
sw.Restart();
191+
for (var a = 0; a < forTime; a++)
192+
{
193+
fsql.Update<Song>().SetSource(songs).ExecuteAffrows();
194+
}
195+
sw.Stop();
196+
sb.AppendLine($"FreeSql Update {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");
197+
198+
//songs = sugar.Queryable<Song>().Take(size).ToList();
199+
//sw.Restart();
200+
//Exception sugarEx = null;
201+
//try
202+
//{
203+
// for (var a = 0; a < forTime; a++)
204+
// sugar.Updateable(songs).ExecuteCommand();
205+
//}
206+
//catch (Exception ex)
207+
//{
208+
// sugarEx = ex;
209+
//}
210+
//sw.Stop();
211+
//sb.AppendLine($"SqlSugar Update {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms" + (sugarEx != null ? $"成绩无效,错误:{sugarEx.Message}" : ""));
212+
}
213+
}
214+
215+
[FreeSql.DataAnnotations.Table(Name = "freesql_song")]
216+
//[SugarTable("sugar_song")]
217+
public class Song
218+
{
219+
[FreeSql.DataAnnotations.Column(IsIdentity = true)]
220+
//[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
221+
public int Id { get; set; }
222+
public DateTime? Create_time { get; set; }
223+
public bool? Is_deleted { get; set; }
224+
public string Title { get; set; }
225+
public string Url { get; set; }
226+
227+
//[SugarColumn(IsIgnore = true)]
228+
public virtual ICollection<Tag> Tags { get; set; }
229+
}
230+
[FreeSql.DataAnnotations.Table(Name = "freesql_song_tag")]
231+
//[SugarTable("sugar_song_tag")]
232+
public class Song_tag
233+
{
234+
public int Song_id { get; set; }
235+
//[SugarColumn(IsIgnore = true)]
236+
public virtual Song Song { get; set; }
237+
238+
public int Tag_id { get; set; }
239+
//[SugarColumn(IsIgnore = true)]
240+
public virtual Tag Tag { get; set; }
241+
}
242+
[FreeSql.DataAnnotations.Table(Name = "freesql_tag")]
243+
//[SugarTable("sugar_tag")]
244+
public class Tag
245+
{
246+
[FreeSql.DataAnnotations.Column(IsIdentity = true)]
247+
//[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
248+
public int Id { get; set; }
249+
public int? Parent_id { get; set; }
250+
//[SugarColumn(IsIgnore = true)]
251+
public virtual Tag Parent { get; set; }
252+
253+
public decimal? Ddd { get; set; }
254+
public string Name { get; set; }
255+
256+
//[SugarColumn(IsIgnore = true)]
257+
public virtual ICollection<Song> Songs { get; set; }
258+
//[SugarColumn(IsIgnore = true)]
259+
public virtual ICollection<Tag> Tags { get; set; }
260+
}
261+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 有关程序集的一般信息由以下
6+
// 控制。更改这些特性值可修改
7+
// 与程序集关联的信息。
8+
[assembly: AssemblyTitle("orm_vs_net40")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("orm_vs_net40")]
13+
[assembly: AssemblyCopyright("Copyright © 2019")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 将 ComVisible 设置为 false 会使此程序集中的类型
18+
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19+
//请将此类型的 ComVisible 特性设置为 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23+
[assembly: Guid("1674bce3-eeb4-4003-a2a7-06f51efaea23")]
24+
25+
// 程序集的版本信息由下列四个值组成:
26+
//
27+
// 主版本
28+
// 次版本
29+
// 生成号
30+
// 修订号
31+
//
32+
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
33+
//通过使用 "*",如下所示:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{1674BCE3-EEB4-4003-A2A7-06F51EFAEA23}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>orm_vs_net40</RootNamespace>
10+
<AssemblyName>orm_vs_net40</AssemblyName>
11+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<Deterministic>true</Deterministic>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="Program.cs" />
45+
<Compile Include="Properties\AssemblyInfo.cs" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj">
49+
<Project>{af9c50ec-6eb6-494b-9b3b-7edba6fd0ebb}</Project>
50+
<Name>FreeSql</Name>
51+
</ProjectReference>
52+
<ProjectReference Include="..\..\Providers\FreeSql.Provider.MySql\FreeSql.Provider.MySql.csproj">
53+
<Project>{28c6a39c-7ae7-4210-b7b0-0970216637a8}</Project>
54+
<Name>FreeSql.Provider.MySql</Name>
55+
</ProjectReference>
56+
<ProjectReference Include="..\..\Providers\FreeSql.Provider.SqlServer\FreeSql.Provider.SqlServer.csproj">
57+
<Project>{b61aac9e-59e9-4f47-bbe3-97ac24112efe}</Project>
58+
<Name>FreeSql.Provider.SqlServer</Name>
59+
</ProjectReference>
60+
</ItemGroup>
61+
<ItemGroup>
62+
<PackageReference Include="Newtonsoft.Json">
63+
<Version>12.0.2</Version>
64+
</PackageReference>
65+
</ItemGroup>
66+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
67+
</Project>

Extensions/FreeSql.Extensions.JsonMap/FreeSql.Extensions.JsonMap.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
55
<Version>0.10.14</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Authors>YeXiangQin</Authors>

Extensions/FreeSql.Extensions.JsonMap/JsonMapCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void UseJsonMap(this IFreeSql that)
3737

3838
that.Aop.ConfigEntityProperty += new EventHandler<Aop.ConfigEntityPropertyEventArgs>((s, e) =>
3939
{
40-
if (e.Property.GetCustomAttribute<JsonMapAttribute>(false) != null)
40+
if (e.Property.GetCustomAttributes(typeof(JsonMapAttribute), false).Any())
4141
{
4242
e.ModifyResult.MapType = typeof(string);
4343
if (_dicTypes.TryAdd(e.Property.PropertyType, true))

Extensions/FreeSql.Extensions.LazyLoading/FreeSql.Extensions.LazyLoading.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
55
<Version>0.10.14</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Authors>YeXiangQin</Authors>

0 commit comments

Comments
 (0)