AppService 层使用nuget 添加 EFCore.BulkExtensions 引用
1 using Abp.Application.Services.Dto; 2 using Abp.Domain.Repositories; 3 using Abp.EntityFrameworkCore.Repositories; 4 using Abp.UI; 5 using EFCore.BulkExtensions; 6 using Microsoft.EntityFrameworkCore; 7 using System; 8 using System.Collections.Generic; 9 using System.Diagnostics;10 using System.Linq;11 using System.Text;12 using System.Threading.Tasks;13 using WebProject.Authorization.Accounts;14 15 namespace WebProject.Article16 {17 public class ArticleAppService : WebProjectAppServiceBase, IArticleAppService18 {19 private readonly IRepository_articleRepository;20 public ArticleAppService(IRepository articleRepository)21 {22 _articleRepository = articleRepository;23 }24 /// 25 /// 批量添加26 /// 27 /// 28 ///29 public string BulkInsert(EntityDto input)30 {31 Stopwatch watch = new Stopwatch();32 watch.Start();33 List list = new List ();34 for (int i = 0; i < input.Id; i++)35 {36 var entity = new Models.Article();37 entity.CateId = 2;38 entity.Title = $"BulkInsert娱乐{1}";39 list.Add(entity);40 }41 42 _articleRepository.GetDbContext().BulkInsert(list);//GetDbContext 需要添加Abp.EntityFrameworkCore.Repositories引用43 watch.Stop();44 45 string time = watch.ElapsedMilliseconds.ToString();46 return time;47 }48 /// 49 /// 批量删除50 /// 51 ///52 public string BulkDelete()53 {54 Stopwatch watch = new Stopwatch();55 watch.Start();56 _articleRepository.GetAll().BatchDelete();57 //_articleRepository.GetAll().Where(m=>m.Id>100).BatchDelete();58 watch.Stop();59 string time = watch.ElapsedMilliseconds.ToString();60 return time;61 }62 /// 63 /// 批量修改64 /// 65 ///66 public string BatchUpdate()67 {68 Stopwatch watch = new Stopwatch();69 watch.Start();70 _articleRepository.GetAll().BatchUpdate(new Models.Article { Title = "Updated娱乐" });71 //_articleRepository.GetAll().Where(m=>m.Id>100).BatchUpdate(new Models.Article { Title = "Updated娱乐" });72 watch.Stop();73 string time = watch.ElapsedMilliseconds.ToString();74 return time;75 }76 77 }78 }