-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed
Copy link
Milestone
Description
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