Compare commits

...

2 Commits

Author SHA1 Message Date
Bunny 9643be09c0 合并 2024-09-03 22:11:35 +08:00
bunny 57eb804feb 🚀 feat(新增): 添加事务使用示例 2024-09-03 22:10:49 +08:00
3 changed files with 7 additions and 13 deletions

View File

@ -1,5 +1,4 @@
using Bunny.Common.Interceptor;
using Bunny.Dao.Entity.Base;
using Bunny.Dao.Entity.Base;
using Bunny.Dao.Entity.System;
using log4net;
using Microsoft.EntityFrameworkCore;

View File

@ -2,7 +2,7 @@
using Bunny.Dao.Common.Constant;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace Bunny.Common.Interceptor;
namespace Bunny.Common.Context.Database;
public class TransactionInterceptor : SaveChangesInterceptor
{

View File

@ -61,22 +61,17 @@ public class BlogService : IBlogService
/// <param name="url"></param>
public void AddBatchBlogs(string url)
{
using var transaction = DbContext.Database.BeginTransaction();
var list = new List<Blog>();
for (var i = 0; i <= 100000; i++)
list.Add(new Blog
{
Url = url,
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
UpdateUserId = Random.Shared.Next(),
CreateUserId = Random.Shared.NextInt64()
});
for (var i = 0; i <= 100; i++)
list.Add(new Blog { Url = $"Blog{i}" });
DbContext.Blogs.AddRange(list);
DbContext.SaveChanges();
transaction.Commit();
}
/// <summary>
/// 批量删除BLog
/// </summary>