假设我有一个DbContext,其中包含以下DbSet:
class Amimals : DbContext
{
public DbSet<Dog> Dogs { get; set; }
public DbSet<Cat> Cats { get; set; }
}
在每个EntityTypeConfiguration中,我正在定义每个DbSet的表,例如:
class DogConfig : EntityTypeConfiguration
{
public DogConfig()
{
this.ToTable("DOG_TABLE");
...
}
}
现在,如果我有表名和DbContext,我该如何获取并使用正确的DbSet?
void foo()
{
string tableName = this.GetTableName();
using(Animals context = new Animals())
{
/* Made up solution */
DbSet animalContext = context.Where(c => c.TableName == tableName);
...
/* Do something with DbSet */
...
}
}
System.MissingMethodException: Constructor on type Microsoft.EntityFrameworkCore.DbSet1 not found
.? - Tyson Gibby