I have a project called Persistance where I have installed Nuget Package called EFCore.BulkExtensions for bulk insert.
I have another project called Application which defines the Interface representing the DBset as below :
Application Project:
public interface IDatabaseService
{
public DbSet<Employee> Employee {get;set;}
public DbSet<Department> Department {get;set;}
public void Save();
public void Insert<T>(IEnumerable<T> lists);
public int ExecuteSP(string procedureName,params object[] parameters);
}
Persistance project :
using EFCore.BulkExtensions;
public class MyDatabaseContext : DbContext,IDatabaseService
{
private readonly IConfiguration _configuration;
public MyDatabaseContext(IConfiguration configuration)
{
_configuration = configuration;
Database.EnsureCreated();
}
public DbSet<Employee> Employee {get;set;}
public DbSet<Department> Department {get;set;}
public void Save()
{
this.SaveChanges();
}
public void Insert<T>(IEnumerable<T> lists)
{
this.BulkInsert(lists);/error here
}
}
Error: type arguments for method DbContextBulkExtensions.BulkInsert(DbContext, IList) cannot be inferrred from the usage.
How can I fix this?
EFCore.BulkExtensions.DbContextBulkExtensionsis available on GitHub.BulkInsert<T>methods require entities to be passed in viaIList<T>collections]1, and not asIEnumerable<T>.Ttowhere T : class, so add that constraint too.So change this:
to this: