문제

I have an EF6.1 EDMX (Database First) model and I am using TPT inheritance for several types (ie. Employee : Person), however, in the generated Model.Context.cs class I only have DbSet<T> classes for my base types and not the inheriting ones. Is there anything that needs to (or can) be done to either the EDMX model or the T4 templates to generate DbSet<T> for the inheriting classes as well?

도움이 되었습니까?

해결책

You can get the subtypes from the context by

context.People.OfType<Employee>()

or you can extend the context by a partial class in which you define properties for subtype DbSets:

partial class Context
{
    public DbSet<Employee> Employees { get; set; }
}

That's much easier than modifying the t4 template because the standard t4 templates can change in future releases, so you'll have to modify them again.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top