我正在使用设计器(VS2012)创建一个 EF5 实体模型,并将 EF5 DbContext 生成器用作代码生成项。
我的模型包含一个派生自另一个(非抽象)的实体。
因此,假设基础实体称为 BaseEntity,派生实体称为 DerivedEntity。
现在我在生成的上下文类中看到,没有
Public DbSet<DerivedEntity> DerivedEntities { get; set; }
定义。
仅有的
Public DbSet<BaseEntity> BaseEntities { get; set; }
被定义为。
这是正常的吗?如果是,我如何查询 linq 中的派生实体?
我习惯这样查询:
using(var ctx = new EntityContainer)
{
var q = from e in ctx.DerivedEntities <-- but this is now not possible since it doesn't exist
select e;
return q.ToList();
}
感谢回复。
编辑:
根据要求,生成的类发布:
public partial class Scheduling
{
public int Id { get; set; }
public string Subject { get; set; }
public System.DateTime BeginDate { get; set; }
public System.DateTime EndDate { get; set; }
}
public partial class TeamScheduling : Scheduling
{
public int TeamId { get; set; }
public Nullable<int> AssignmentId { get; set; }
public virtual Team Team { get; set; }
public virtual Assignment Assignment { get; set; }
}
public partial class EntityContainer : DbContext
{
public EntityContainer()
: base("name=EntityContainer")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Team> Teams { get; set; }
public DbSet<Location> Locations { get; set; }
public DbSet<Country> Countries { get; set; }
public DbSet<Assignment> Assignments { get; set; }
public DbSet<ProductType> ProductTypes { get; set; }
public DbSet<AssignmentPreference> AssignmentPreferences { get; set; }
public DbSet<Scheduling> Schedulings { get; set; }
}
如您所见,EntityContainer 类不包含
public DbSet<TeamScheduling> TeamSchedulings { get; set; }