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

Inefficient query #23004

Closed
Dev0033 opened this issue Oct 15, 2020 · 1 comment
Closed

Inefficient query #23004

Dev0033 opened this issue Oct 15, 2020 · 1 comment

Comments

@Dev0033
Copy link

Dev0033 commented Oct 15, 2020

I noticed that EF is doing a rather inefficient query
If I made query like:

var baseQuery = db.Blogs.FromSqlRaw("SELECT * FROM Blogs");

var q1 = baseQuery.Select(b => new Test() { Id = b.BlogId }).ToList();

public class Test
  {
    public int Id { get; set; }
  }

Query to the server would be:
SELECT * FROM Blogs

It should be:
SELECT [b].[BlogId] AS [Id]
FROM
(
SELECT * FROM Blogs
) AS [b]

If I add Take-parameter to ef query

var q2 = baseQuery.Select(b => new Test() { Id = b.BlogId }).Take(100).ToList();

Query to the server would be:
exec sp_executesql N'SELECT TOP(@__p_1) [b].[BlogId] AS [Id]
FROM (
SELECT * FROM Blogs
) AS [b]',N'@__p_1 int',@__p_1=100
As it should be.

So why ef can't capsulate sql query correctly without Take-parameter?
Sample:
EFGetStarted.zip

@smitpatel
Copy link
Member

Duplicate of #16079

@smitpatel smitpatel marked this as a duplicate of #16079 Oct 15, 2020
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
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