Reputation: 6868
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?
Upvotes: 1
Views: 252
Reputation: 155523
EFCore.BulkExtensions.DbContextBulkExtensions
is available on GitHub.
BulkInsert<T>
methods require entities to be passed in via IList<T>
collections]1, and not as IEnumerable<T>
.T
to where T : class
, so add that constraint too.So change this:
public void Insert<T>( IEnumerable<T> lists )
{
this.BulkInsert(lists);/error here
}
to this:
public void Insert<T>( IList<T> entities )
where T : class
{
this.BulkInsert( entities: entities );
}
Upvotes: 3