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

Allow creation of a DbCommand from an EF IQueryable #19358

Closed
ajcvickers opened this issue Dec 18, 2019 · 5 comments
Closed

Allow creation of a DbCommand from an EF IQueryable #19358

ajcvickers opened this issue Dec 18, 2019 · 5 comments
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@ajcvickers
Copy link
Member

See #19335

For example:

var query = context.Blogs.Where(b => b.Published);
var command = query.CreateDbCommand();

Things to note:

  • The command providers access to the SQL query string and parameters.
  • The created command is not the actual command that EF will use if the query is then executed. A new command will be created for this, but using the same mechanism.
  • The created command can likely be executed, but will be doing so outside of the normal EF environment and so may not have exactly the same behavior.
@ajcvickers ajcvickers added this to the 5.0.0 milestone Dec 18, 2019
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Dec 18, 2019
@ajcvickers ajcvickers self-assigned this Dec 18, 2019
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview1 Mar 13, 2020
@Giorgi
Copy link
Contributor

Giorgi commented Mar 16, 2020

Looking at the Source of CreateDbCommand it looks like that the command must be executed before the cache is populated. Is there a way to get the command without actually executing the IQueryable ?

@ajcvickers
Copy link
Member Author

@Giorgi What "cache" are you referring to?

@Giorgi
Copy link
Contributor

Giorgi commented Mar 16, 2020

I mean this code:

public virtual DbCommand CreateDbCommand()

@Giorgi
Copy link
Contributor

Giorgi commented Mar 16, 2020

The code that I linked to in my first comment calls source.Provider.Execute so I guess that is needed to populate the _relationalCommandCache

@ajcvickers
Copy link
Member Author

@Giorgi The code for CreateDbCommand does not execute the command. Also, as far as I can tell, it will populate/use the command cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

2 participants