0

I am using ASP.NET Zero to insert large amounts of data from Excel into the database and it is slow. So I thought of using Entity Framework Extensions for BulkInsert but don't really know how to use it.. I get an error

The type arguments for the method DbContextBulkExtensions.BulkInsert can not be inferred from usage

This is my code.. Any help please?

private readonly IRepository<InventoryBalance> _repository;
   
public void Create(InventoryBalance input)
{
    _repository.GetDbContext().BulkInsert(input);
} 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ckeedee
  • 87
  • 2
  • 9
  • Am using https://github.com/borisdj/EFCore.BulkExtensions and not https://entityframework-extensions.net..However i have tried changing it to but same errors. public void Create(IEnumerable inputs) { _repository.GetDbContext().BulkInsert(inputs); } – ckeedee Oct 07 '20 at 08:37

1 Answers1

0

The BulkInsert method takes an IEnumerable<T> parameter. Try changing your code to something like this and pass it a collection of inputs instead of just one.

public void Create(IEnumerable<InventoryBalance> inputs)
{
    _repository.GetDbContext().BulkInsert(inputs);
} 

Also note that you will need to set up the context factory somewhere. Try adding this line to your repository's constructor.

EntityFrameworkManager.ContextFactory = context => context;

https://entityframework-extensions.net/context-factory

Connell.O'Donnell
  • 3,603
  • 11
  • 27
  • 61