The behavior of Distinct in SqlServer and Cosmos is inconsistent
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start by running the supplied LINQ OrderBy(...).Distinct().ToQueryString() reproduction against both Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Cosmos at the reported EF Core version. Compare the generated SQL with the documented Distinct behavior, then determine the intended cross-provider result. Done means the behavior is aligned or the provider difference is clearly documented and covered by appropriate tests.
Written by the indexing model from the issue text.
Description
https://docs.microsoft.com/en-us/dotnet/api/system.linq.queryable.distinct?view=net-6.0
https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-6.0/whatsnew#distinct-queries
Include your code
[Table("Table_1")]
public partial class Table1
{
[Key]
public int Id { get; set; }
public DateTime CreateTime { get; set; }
}
public partial class TestContext : DbContext
{
public TestContext()
{
}
public TestContext(DbContextOptions<TestContext> options)
: base(options)
{
}
public virtual DbSet<Table1> Table1 { get; set; }
}
var services = new ServiceCollection();
services.AddDbContext<TestContext>();
var serviceProvider = services.BuildServiceProvider();
var testContext = serviceProvider.GetRequiredService<TestContext>();
var sql = testContext.Table1.OrderBy(a => a.Id).Distinct().ToQueryString();
Console.WriteLine(sql);
Sql Server Behavior
SELECT DISTINCT [t].[Id], [t].[CreateTime]
FROM [Table_1] AS [t]
Cosmos Behavior
SELECT DISTINCT c
FROM root c
WHERE (c["Discriminator"] = "Table1")
ORDER BY c["Id"]
Include provider and version information
EF Core version:6.0.0-rc.2.21480.5
Database provider: Microsoft.EntityFrameworkCore.SqlServer/Microsoft.EntityFrameworkCore.Cosmos
Target framework: .NET 6.0
Operating system:Win11
IDE: Visual Studio 2022 17.0
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100