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

distinct not emitted in sql when selecting a declared type #7699

Closed
tschmit opened this issue Feb 23, 2017 · 1 comment
Closed

distinct not emitted in sql when selecting a declared type #7699

tschmit opened this issue Feb 23, 2017 · 1 comment

Comments

@tschmit
Copy link

tschmit commented Feb 23, 2017

The distinct is not translated into sql when used after a Select(x => new Type {}).
The distinct is well translated with an anonymous type Select(x => new {}).

Steps to reproduce

public class ThirdParty {
    public int ThirdPartyId { get; set; }
    public string Name { get; set; }
    public string NormalizedName { get; set; }
}

public class MyDataContext : DbContext {
    public DbSet<ThirdParty> ThirdParties { get; set; }
}

public class DTOTP {
    public String NormName { get; set; }
}

//The following fails: no distinct in the sql query (no effect at all in fact, distinct is totally ignored)
return _ctx.ThirdParties.Where(x => (x.NormalizedName ?? x.Name).Contains(qName)).
                Select(x => new DTOTP { NormName = x.NormalizedName ?? x.Name }).
                Distinct().
                OrderBy(x => x.NormName).ToList();

//The following runs: Distinct() is translated in the sql query emitted
return _ctx.ThirdParties.Where(x => (x.NormalizedName ?? x.Name).Contains(qName)).
                Select(x => new { NormName = x.NormalizedName ?? x.Name }).
                Distinct().
                OrderBy(x => x.NormName).ToList().
                Select(x => new DTOTP { NormName = x.NormName }).ToList();

Further technical details

EF Core version: 1.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: windows 10
IDE: Visual Studio 2015

@smitpatel
Copy link
Contributor

dupe of #7234

@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

4 participants