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

Cosmos: Non-generic Find/FindAsync on DbContext is not translated to ReadItem #33881

Closed
ajcvickers opened this issue Jun 3, 2024 · 0 comments · Fixed by #33896
Closed

Cosmos: Non-generic Find/FindAsync on DbContext is not translated to ReadItem #33881

ajcvickers opened this issue Jun 3, 2024 · 0 comments · Fixed by #33896
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@ajcvickers
Copy link
Member

Using non-generic Find, such as await context.FindAsync(typeof(Post), 77); is not translated to ReadItem and instead results in a normal query:

SELECT c
FROM root c
WHERE ((c["Discriminator"] = "Post") AND (c["Id"] = @__p_0))
OFFSET 0 LIMIT 1

Repro

using (var context = new AppDbContext())
{
    await context.Database.EnsureDeletedAsync();
    await context.Database.EnsureCreatedAsync();

    context.Add(new Post { Id = 77 } );
    
    await context.SaveChangesAsync();
}

using (var context = new AppDbContext())
{
    var x = await context.FindAsync(typeof(Post), 77);
}

public class AppDbContext : DbContext
{
    public DbSet<Post> Posts => Set<Post>();

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseCosmos(
                "https://localhost:8081",
                "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
                "EFDatabase")
            .LogTo(Console.WriteLine, LogLevel.Information)
            .EnableSensitiveDataLogging();
}

public class Post
{
    public int Id { get; set; }
    public string? Title { get; set; }
}
@ajcvickers ajcvickers added type-bug closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. area-query area-cosmos labels Jun 3, 2024
@ajcvickers ajcvickers self-assigned this Jun 3, 2024
@ajcvickers ajcvickers added this to the 9.0.0 milestone Jun 3, 2024
ajcvickers added a commit that referenced this issue Jun 4, 2024
This change stops using `ReadItemExpression`, since it does not do any shaper processing, and instead uses `SelectExpression` as for other queries. This allows processing of auto-Includes for owned types, even if Find is being translated to `ReadItem`.

This is somewhat hacky now, but it likely to change again as the processing for Includes and/or complex types is changed. For now, it's a reasonable way to get an important feature working.

Fixes #24202

In addition, the pattern matching has been updated to detect calls to non-generic Find.

Fixes #33881
ajcvickers added a commit that referenced this issue Jun 5, 2024
This change stops using `ReadItemExpression`, since it does not do any shaper processing, and instead uses `SelectExpression` as for other queries. This allows processing of auto-Includes for owned types, even if Find is being translated to `ReadItem`.

This is somewhat hacky now, but it likely to change again as the processing for Includes and/or complex types is changed. For now, it's a reasonable way to get an important feature working.

Fixes #24202

In addition, the pattern matching has been updated to detect calls to non-generic Find.

Fixes #33881
@ajcvickers ajcvickers modified the milestones: 9.0.0, 9.0.0-preview6 Jun 7, 2024
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
@roji roji modified the milestones: 9.0.0-preview6, 9.0.0 Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants