C#_EFCore学习

1、批量增加,删除,更新

导包

包:Zack.EFCore.Batch

使用方法

nuget.org官网中输入包名,选择数据库对应的包安装(Zack.EFCore.Batch是一个基础包,安装数据库对应的包就会包含基础包),看对应的官方文档的使用方法

//增加
ctx.BulkInsert(books)

//删除
await ctx.DeleteRangeAsync<Book>(b=>b.Price>n||b.AuthorName=="Diff");

//更新Set(b=>b.Key,b.value)
await ctx.BatchUpdate<Book>()
    .Set(b=>b.Price,b.Price+3)
   	.Set(b=>b.Title,b=>s)
    .Set(b=>b.AuthorName,b=>b.Title.Substring(3,2)+b.AuthorName.ToUpper())
    .Set(b=>b.PubTime,b=>DateTime.Now)
    .Where(b=>b.Id>n||b.ArthorName.StartsWith("Diff")).ExecuteAsync()    
posted on 2022-09-03 17:54  Jeffrey~~  阅读(152)  评论(0编辑  收藏  举报