Skip to content

Support for defining query in query types #3932

@divega

Description

@divega

The idea is to support customizing the source query for a specific set at the model level, e.g.:

modelBuilder.Entity<Product>()
    .FromSql("SELECT Id, UPPER(Name) AS Name FROM Products");

Or using LINQ and some extra state such as the DbContext

modelBuilder.Entity<Product>()
    .FromQuery<MyDbContext>((source, context) => 
        source.Where(e => EF.Property(e, "TentantId") == context.TenantId);

One possible advantage of having this in the model is that we would take it into account even if the entity type is included in the query as part of a navigation, e.g. it would make it possible to add additional filters on navigation properties even if they are populated using Include().

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueThis issue should be relatively straightforward to fix.help wantedThis issue involves technologies where we are not experts. Expert help would be appreciated.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions