Compare commits
2 Commits
6d1b642dac
...
9643be09c0
Author | SHA1 | Date |
---|---|---|
|
9643be09c0 | |
|
57eb804feb |
|
@ -1,5 +1,4 @@
|
||||||
using Bunny.Common.Interceptor;
|
using Bunny.Dao.Entity.Base;
|
||||||
using Bunny.Dao.Entity.Base;
|
|
||||||
using Bunny.Dao.Entity.System;
|
using Bunny.Dao.Entity.System;
|
||||||
using log4net;
|
using log4net;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
using Bunny.Dao.Common.Constant;
|
using Bunny.Dao.Common.Constant;
|
||||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
|
|
||||||
namespace Bunny.Common.Interceptor;
|
namespace Bunny.Common.Context.Database;
|
||||||
|
|
||||||
public class TransactionInterceptor : SaveChangesInterceptor
|
public class TransactionInterceptor : SaveChangesInterceptor
|
||||||
{
|
{
|
|
@ -61,22 +61,17 @@ public class BlogService : IBlogService
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
public void AddBatchBlogs(string url)
|
public void AddBatchBlogs(string url)
|
||||||
{
|
{
|
||||||
|
using var transaction = DbContext.Database.BeginTransaction();
|
||||||
var list = new List<Blog>();
|
var list = new List<Blog>();
|
||||||
for (var i = 0; i <= 100000; i++)
|
|
||||||
list.Add(new Blog
|
for (var i = 0; i <= 100; i++)
|
||||||
{
|
list.Add(new Blog { Url = $"Blog{i}" });
|
||||||
Url = url,
|
|
||||||
CreateTime = DateTime.Now,
|
|
||||||
UpdateTime = DateTime.Now,
|
|
||||||
UpdateUserId = Random.Shared.Next(),
|
|
||||||
CreateUserId = Random.Shared.NextInt64()
|
|
||||||
});
|
|
||||||
|
|
||||||
DbContext.Blogs.AddRange(list);
|
DbContext.Blogs.AddRange(list);
|
||||||
DbContext.SaveChanges();
|
DbContext.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 批量删除BLog
|
/// 批量删除BLog
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue