Here is my dbcontext
public partial class MyDbContext : DbContext
{
//dbset 1
public DbSet<Customer> Customers { get; set; }
//dbset 2
public DbSet<Order> Orders { get; set; }
}
I want to pass my models i mean Customer
and order
outside MyDbContext
.something like this :
public partial class MyDbContext<T> : DbContext
{
public DbSet<T> <T>{ get; set; }
}
And a function to get the list of entities to add to my context like this
addEntityToDbContext(Customer)
addEntityToDbContext(Orders)
Is it possible?
I am using EF Core .
I'm not sure what your question is? But DbContext has a generic DbSet method already built in?
public virtual DbSet<TEntity> Set<TEntity>() where TEntity : class =>
(DbSet<TEntity>)((IDbSetCache)this).GetOrAddSet(DbContextDependencies.SetSource, typeof(TEntity));