EF添加。Entity Framework添加。abp vnext ef 添加,批量添加的封装 电脑版发表于:2022/4/25 21:14 **EF的添加如下,代码比较添加:** ``` ShipEntities se = new ShipEntities(); se.Users.Add(user); se.SaveChanges(); ``` **方法2:** ``` ShipEntities se = new ShipEntities(); se.Entry(user).State = System.Data.EntityState.Added; se.SaveChanges(); ``` ### abp vnext ef 批量添加的封装 注意异步状态下断点调试很有可能有异常情况,所以可以先直接执行不调试 ``` /// <summary> /// 封装的批量添加方法 /// </summary> /// <param name="entitys"></param> /// <returns></returns> public async Task<int> BatchAddAsync(List<TEntity> entitys) { var getDbContext = await GetDbContextAsync(); foreach (TEntity item in entitys) { getDbContext.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Added; } return await getDbContext.SaveChangesAsync(); } ```