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 no longer supports Dictionary with TValue type of primitive collection #34105

Closed
damieng opened this issue Jun 27, 2024 · 0 comments · Fixed by #34312
Closed

Cosmos no longer supports Dictionary with TValue type of primitive collection #34105

damieng opened this issue Jun 27, 2024 · 0 comments · Fixed by #34312
Labels
area-cosmos closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression type-bug
Milestone

Comments

@damieng
Copy link

damieng commented Jun 27, 2024

Previously, in EF 8, you could map a property to type Dictionary<string, string[]> and access the properties correctly like this:

var db = new MyDbContext();
var x = await db.Entities.FirstAsync();
Console.WriteLine(string.Join(",", x.Items["Number"]));

internal class Entity
{
    public Guid id { get; set; }
    public Dictionary<string, string[]> Items { get; set; } = new ();
}

internal class MyDbContext : DbContext
{
    public DbSet<Entity> Entities { get; set; } = null!;

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseCosmos("https://localhost:8081", "your-account-key", "SampleDB");
}

In current main branch instead this give a cast error:

Unhandled exception. System.InvalidCastException: Unable to cast object of type 'Microsoft.EntityFrameworkCore.ChangeTracking.ListOfReferenceTypesComparer`2[System.String[],System.String]' to type 'Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1[System.String[]]'.
   at lambda_method207(Closure, Dictionary`2)
   at Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1.Snapshot(T instance) in F:\src\ef-core9\src\EFCore\ChangeTracking\ValueComparer`.cs:line 336
   at lambda_method196(Closure, InternalEntityEntry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.OriginalValues..ctor(InternalEntityEntry entry) in F:\src\ef-core9\src\EFCore\ChangeTracking\Internal\InternalEntityEntry.OriginalValues.cs:line 16
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.EnsureOriginalValues() in F:\src\ef-core9\src\EFCore\ChangeTracking\Internal\InternalEntityEntry.cs:line 1208
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntrySubscriber.SnapshotAndSubscribe(InternalEntityEntry entry) in F:\src\ef-core9\src\EFCore\ChangeTracking\Internal\InternalEntityEntrySubscriber.cs:line 31
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTrackingFromQuery(IEntityType baseEntityType, Object entity, ISnapshot& snapshot) in F:\src\ef-core9\src\EFCore\ChangeTracking\Internal\StateManager.cs:line 339
   at Microsoft.EntityFrameworkCore.Query.QueryContext.StartTracking(IEntityType entityType, Object entity, ISnapshot& snapshot) in F:\src\ef-core9\src\EFCore\Query\QueryContext.cs:line 154
   at lambda_method4(Closure, QueryContext, JObject)
   at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.CosmosShapedQueryCompilingExpressionVisitor.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync() in F:\src\ef-core9\src\EFCore.Cosmos\Query\Internal\CosmosShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs:line 269
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken) in F:\src\ef-core9\src\EFCore\Query\ShapedQueryCompilingExpressionVisitor.cs:line 152
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken) in F:\src\ef-core9\src\EFCore\Query\ShapedQueryCompilingExpressionVisitor.cs:line 164
   at Program.<Main>$(String[] args) in F:\src\ef-core9\ConsoleApp1\Program.cs:line 4
   at Program.<Main>(String[] args)

I suspect this is a regression via #33456.

This also happens if using List etc.

EF Core version: main@1847e1e
Database provider: (e.g. Microsoft.EntityFrameworkCore.Cosmos)
Target framework: (e.g. .NET 9.0)
Operating system: Windows 11
IDE: Rider 2024.1.3

@damieng damieng changed the title Cosmos no longer supports Dictionary with TValue type of array Cosmos no longer supports Dictionary with TValue type of primitive collection Jun 27, 2024
@ajcvickers ajcvickers added this to the 9.0.0 milestone Jul 1, 2024
ajcvickers added a commit that referenced this issue Jul 29, 2024
Fixes #34105

This code will be consolidated with the relational UTF8 JSON code when #29825 is implemented. For now, just adding back what was already in Cosmos.
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 29, 2024
ajcvickers added a commit that referenced this issue Jul 29, 2024
Fixes #34105

This code will be consolidated with the relational UTF8 JSON code when #29825 is implemented. For now, just adding back what was already in Cosmos.
ajcvickers added a commit that referenced this issue Aug 2, 2024
Fixes #34105

This code will be consolidated with the relational UTF8 JSON code when #29825 is implemented. For now, just adding back what was already in Cosmos.
@ajcvickers ajcvickers modified the milestones: 9.0.0, 9.0.0-rc1 Aug 21, 2024
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
@roji roji modified the milestones: 9.0.0-rc1, 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 closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants