EntityFramework.Docs icon indicating copy to clipboard operation
EntityFramework.Docs copied to clipboard

Define inheritance hierarchy as stated in the limitations

Open markarnolditpro opened this issue 8 years ago • 3 comments

Filters can only be defined for the root Entity Type of an inheritance hierarchy .
Please define inheritance hierarchy and provide a simple example of the limitation. Thanks!


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

markarnolditpro avatar May 18 '18 09:05 markarnolditpro

@markarnolditpro It just means mapped classes that use normal class inheritance:

public class Document
{
}
public class Blog : Document
{
}

If Document and Blog are mapped, then the filter can only be applied to Document, not to Blog.

ajcvickers avatar Jun 13 '18 20:06 ajcvickers

Is there a "Global Query Projector" ? to include or exclude some table fields ? If I have a column for each culture of a localized field I would use such a global option to select the correct field according to current selected culture.

LucaGabi avatar Nov 25 '18 19:11 LucaGabi

I have an EF Core set of entities where each entity inherits from a BaseEntity, which contains some shared global properties (Id, IsDeleted, etc). By default, this gets mapped to a Azure SQL database as Table per Concrete Type which is great.

However, when I add a query filter as per the example:

modelBuilder.Entity<BaseEntity>().HasQueryFilter(p => !p.IsDeleted);

on the next migration EF wants to drop all my tables and create a single table called BaseEntity which is the Table Per Hierachy pattern.

Is this expected behaviour? Any way to avoid it?

EDIT: This is happening because modelBuilder.Entity() adds BaseEntity to the model, which seems to force EF Core to use TPH since TPC isn't supported yet... hmm.

Dondudu avatar Jul 27 '19 11:07 Dondudu