Expression.Constant reference to DbSet causes translation failure
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start from the LINQ query shown in the issue and run it against EF Core 3.0 with MSSQL 2017 or Azure SQL, comparing the generated SQL with EF Core 2.2. The issue is resolved when the DbSet.Any expression translates to a valid EXISTS-style SQL predicate instead of a list of entity objects.
Written by the indexing model from the issue text.
Description
The following query works perfectly fine on EFCore 2.2, but fails on EFCore 3.0:
(running against MSSQL 2017, or Azure SQL)
var query = from p1 in context.MyEntities
where (p1.MasterCIRId == userContext.CIRId)
&& (p1.IsActive == true)
&& !context.MyEntities.Any(p2 => p2.EntityKey == p1.EntityKey)
select p1;
Running the query on 2.2 translates nicely into a 'where exists ..' clause in the SQL, whilst 3.0 creates a where clause, passing in a list of DbMyEntity classes which logically cannot be translated into valid SQL.
The entity class is pretty straightforward:
public class DbMyEntity()
{
public virtual ICollection<DbConditionEntityList> ConditionEntityLists { get; set; }
[ForeignKey("MasterCIRId")]
public virtual DbCIR MasterCIR { get; set; }
[Column("MasterCIRId", Order = 1, TypeName = "int")]
[Required]
public int MasterCIRId { get; set; }
[Column("IsActive", Order = 2, TypeName = "bit")]
[Required]
public bool IsActive { get; set; }
[Column("EntityKey", Order = 3, TypeName = "int")]
[Required]
public int EntityKey { get; set; }
}
- 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