mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	## v0.3.27
- 增加 行级锁功能,适用修改实体; - 增加 FreeSql.Repository 默认依赖注入的方式,同时保留原有 Autofac; - 优化 FreeSql.Repository Insert 逻辑,参考了 FreeSql.DbContext; - 优化 FreeSql.IUpdate 参照 IInsert 对大批量更新,拆分执行; - 修复 FreeSql.IInsert ClearData 重复利用的 bug(使用 IgnoreColumns 进行大批量插入时会发生);
This commit is contained in:
		@@ -102,6 +102,27 @@ namespace orm_vs
 | 
			
		||||
			Console.Write(sb.ToString());
 | 
			
		||||
			sb.Clear();
 | 
			
		||||
 | 
			
		||||
			Console.WriteLine("更新:");
 | 
			
		||||
			Update(sb, 1000, 1);
 | 
			
		||||
			Console.Write(sb.ToString());
 | 
			
		||||
			sb.Clear();
 | 
			
		||||
			Update(sb, 1000, 10);
 | 
			
		||||
			Console.Write(sb.ToString());
 | 
			
		||||
			sb.Clear();
 | 
			
		||||
 | 
			
		||||
			Update(sb, 1, 1000);
 | 
			
		||||
			Console.Write(sb.ToString());
 | 
			
		||||
			sb.Clear();
 | 
			
		||||
			Update(sb, 1, 10000);
 | 
			
		||||
			Console.Write(sb.ToString());
 | 
			
		||||
			sb.Clear();
 | 
			
		||||
			Update(sb, 1, 50000);
 | 
			
		||||
			Console.Write(sb.ToString());
 | 
			
		||||
			sb.Clear();
 | 
			
		||||
			Update(sb, 1, 100000);
 | 
			
		||||
			Console.Write(sb.ToString());
 | 
			
		||||
			sb.Clear();
 | 
			
		||||
 | 
			
		||||
			Console.WriteLine("测试结束,按任意键退出...");
 | 
			
		||||
			Console.ReadKey();
 | 
			
		||||
		}
 | 
			
		||||
@@ -150,12 +171,12 @@ namespace orm_vs
 | 
			
		||||
 | 
			
		||||
			sw.Restart();
 | 
			
		||||
			for (var a = 0; a < forTime; a++) {
 | 
			
		||||
				//fsql.Insert(songs).ExecuteAffrows();
 | 
			
		||||
				using (var db = new FreeSongContext()) {
 | 
			
		||||
					//db.Configuration.AutoDetectChangesEnabled = false;
 | 
			
		||||
					db.Songs.AddRange(songs.ToArray());
 | 
			
		||||
					db.SaveChanges();
 | 
			
		||||
				}
 | 
			
		||||
				fsql.Insert(songs).ExecuteAffrows();
 | 
			
		||||
				//using (var db = new FreeSongContext()) {
 | 
			
		||||
				//	//db.Configuration.AutoDetectChangesEnabled = false;
 | 
			
		||||
				//	db.Songs.AddRange(songs.ToArray());
 | 
			
		||||
				//	db.SaveChanges();
 | 
			
		||||
				//}
 | 
			
		||||
			}
 | 
			
		||||
			sw.Stop();
 | 
			
		||||
			sb.AppendLine($"FreeSql Insert {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");
 | 
			
		||||
@@ -183,7 +204,46 @@ namespace orm_vs
 | 
			
		||||
			sw.Stop();
 | 
			
		||||
			sb.AppendLine($"EFCore Insert {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms\r\n");
 | 
			
		||||
		}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		static void Update(StringBuilder sb, int forTime, int size) {
 | 
			
		||||
			Stopwatch sw = new Stopwatch();
 | 
			
		||||
 | 
			
		||||
			var songs = fsql.Select<Song>().Limit(size).ToList();
 | 
			
		||||
			sw.Restart();
 | 
			
		||||
			for (var a = 0; a < forTime; a++) {
 | 
			
		||||
				fsql.Update<Song>().SetSource(songs).ExecuteAffrows();
 | 
			
		||||
			}
 | 
			
		||||
			sw.Stop();
 | 
			
		||||
			sb.AppendLine($"FreeSql Update {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");
 | 
			
		||||
 | 
			
		||||
			songs = sugar.Queryable<Song>().Take(size).ToList();
 | 
			
		||||
			sw.Restart();
 | 
			
		||||
			Exception sugarEx = null;
 | 
			
		||||
			try {
 | 
			
		||||
				for (var a = 0; a < forTime; a++)
 | 
			
		||||
					sugar.Updateable(songs).ExecuteCommand();
 | 
			
		||||
			} catch (Exception ex) {
 | 
			
		||||
				sugarEx = ex;
 | 
			
		||||
			}
 | 
			
		||||
			sw.Stop();
 | 
			
		||||
			sb.AppendLine($"SqlSugar Update {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms" + (sugarEx != null ? $"成绩无效,错误:{sugarEx.Message}" : ""));
 | 
			
		||||
 | 
			
		||||
			using (var db = new SongContext()) {
 | 
			
		||||
				songs = db.Songs.Take(size).AsNoTracking().ToList();
 | 
			
		||||
			}
 | 
			
		||||
			sw.Restart();
 | 
			
		||||
			for (var a = 0; a < forTime; a++) {
 | 
			
		||||
 | 
			
		||||
				using (var db = new SongContext()) {
 | 
			
		||||
					//db.Configuration.AutoDetectChangesEnabled = false;
 | 
			
		||||
					db.Songs.UpdateRange(songs.ToArray());
 | 
			
		||||
					db.SaveChanges();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			sw.Stop();
 | 
			
		||||
			sb.AppendLine($"EFCore Update {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms\r\n");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	[FreeSql.DataAnnotations.Table(Name = "freesql_song")]
 | 
			
		||||
	[SugarTable("sugar_song")]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user