【发布时间】:2014-10-10 18:24:18
【问题描述】:
假设我有一个带有以下 DbSet 的 DbContext
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 */
...
}
}
【问题讨论】:
标签: c# linq entity-framework reflection