Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LeroyK opened this issue Mar 16, 2018 · 1 comment
Open

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

LeroyK opened this issue Mar 16, 2018 · 1 comment

Comments

@LeroyK
Copy link

LeroyK commented Mar 16, 2018

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);
@ajcvickers
Copy link
Member

@LeroyK This is an interesting idea. We discussed it in triage and we're going to put it on the backlog for now. However, it could be that the same functionality might be better implemented in a different place, such as in a defining query although this would likely require the defining query to be parameterized. It might also be covered by global query hints. Then, of course, we hope to have better support for temporal tables without needing these things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants