Skip to content

Proposal: Add overload to .Include for custom SQL query #11296

Open
@LeroyK

Description

@LeroyK

We currently use DbSet<>.FromSql to execute temporal queries on System-Versioned Temporal Tables, this works fine, but we can't use .Include in these queries, since you can't specify a SQL query for included entities. There is a workaround, which is to select all of the included entities beforehand using .FromSql so they are already in the EF Core model. However, this is quite cumbersome to do and involves a lot of roundtrips to the DB.

I would like to propose an enhancement that adds an overload on .Include that allows the SQL query to be provided, similar to .FromSql on DbSet<>.

Example:

var temporalQueryClause = " FOR SYSTEM_TIME AS OF '2015-09-01 T10:00:00.7230011'";
var users =
    db.Users
    .FromSql("SELECT * FROM [dbo].[User]" + temporalQueryClause)
    .Include(x => x.Login, "SELECT * FROM [dbo].[Login]" + temporalQueryClause);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions