I use EF Core in my project and have a base class Person.
In addition to the Person, I have multiple views inherited from the base class because I want the fields and relationships of the base class.
The views contains computed column, that i defined in the CREATE statement of the view, mostly status or Ids
//Simplified for the example
public class Person {
public Guid Id {get; set;}
public Guid BId {get; set;}
public Class B { get; set;}
}
public class PersonView : Person {
public PersonStatus Status {get; set;}
}
public class PersonNextView : Person {
public PersonStatus Status {get; set;}
public Guid? NextId {get; set;}
public virtual Person? {get; set;}
}
The problem is that EF Core makes Discriminator on my query when I query one of the Classes above, which seems strange.
// Query:
_context.PersonView.Where(...).ToListAsync(...);
This will be translated with Discriminator, but shouldn't EF Core only query the view?
Especially on .Includes(...) are big SQL queries created, with Joins on all Views.
Questions:
Why do I make inheritance views? Because I use HotChocolate as my GraphQL API and use the view types to generate filters/sorting for them.
[UseFiltering(typeof(PersonView))]
[UseSorting(typeof(PersonView))]
public IQueryable<PersonView> PersonFilter(...) {
...
}
Database used: SQL Server