首页 新闻 会员 周边 捐助

.net code使用Z.EntityFramework.Plus.BulkInsertAsync报错

0
悬赏园豆:10 [待解决问题]

.net code使用Z.EntityFramework.Plus.BulkInsertAsync报错

using Z.EntityFramework.Plus;

    private readonly TDbContext _context;
    private DbSet<TEntity> _entities;
    public virtual DbSet<TEntity> Entities => _entities ?? (_entities = _context.Set<TEntity>());

    public EfCoreRepository(TDbContext context)
    {
        _context = context;
    }
   /// <summary>
    /// 批量插入
    /// </summary>
    /// <param name="entities"></param>
    /// <returns></returns>
    public async Task BulkInsertAsync(IEnumerable<TEntity> entities)
    {
          await _context.BulkInsertAsync(entities);
    }

DbSet也一样报错

     /// <summary>
    /// 批量插入
    /// </summary>
    /// <param name="entities"></param>
    /// <returns></returns>
    public async Task BulkInsertAsync(IEnumerable<TEntity> entities)
    {
          await Entities.BulkInsertAsync(entities);
    }

System.Exception: A default DbContext context must exist, or a context factory must be provided (EntityFrameworkManager.ContextFactory). This setting is required for some additional features. Read more: http://entityframework-extensions.net/context-factory
   at Z.EntityFramework.Extensions.EntityFrameworkManager.(DbContext , BulkOperation )
   at   . [  ](BulkOperation1 this, DbContext , IEntityType , IEnumerable1  )
   at   . [  ](BulkOperation1 this, DbContext , IEntityType , IEnumerable1 , BulkOperationActionType )
   at   . [  ](DbContext this, IEntityType , IEnumerable1 , Action1 , Boolean )
   at   . [  ](DbContext this, IEnumerable1 , Action1 )
   at DbContextExtensions. 1. ()    at System.Threading.Tasks.Task.InnerInvoke()    at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)    at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location where exception was thrown ---    at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location where exception was thrown ---    at DbContextExtensions.BulkInsertAsync[T](DbContext this, IEnumerable1 entities, Action1 options, CancellationToken cancellationToken)    at TM.Core.Domains.EfCoreRepository2.BulkInsertAsync(IEnumerable`1 entities) in C:\Users\86156\Desktop\tmsf\framework\src\BuildingBlocks\TM.Core\Domains\EfCoreRepository.cs:line 282
   at TM.Live.Services.Product.Services.SpuService.AddAsync(OperateRequest request, Int64 storeId, String realName) in C:\Users\86156\Desktop\tmsf\modules\live\src\Services\TM.Live.Services.Product\Services\SpuService.cs:line 384}

冼晓松的主页 冼晓松 | 初学一级 | 园豆:192
提问于:2020-04-16 23:47
< >
分享
所有回答(1)
0

使用的包是EFCore.BulkExtensions么?版本是多少

芝麻的西瓜 | 园豆:206 (菜鸟二级) | 2020-05-17 23:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册