Skip to content

8.0.0 From HasColumnType("jsonb") to OwnsOne(.., d => d.ToJson()) for Dyctionary<enum,string> #3000

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

Closed
max1997dc opened this issue Nov 29, 2023 · 2 comments

Comments

@max1997dc
Copy link

When pass from Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 to Npgsql.EntityFrameworkCore.PostgreSQL 8.0.0

Project File:
...



all
runtime; build; native; contentfiles; analyzers; buildtransitive



all runtime; build; native; contentfiles; analyzers; buildtransitive ...

Fluent EntityTypeConfiguration:
...
#if NET8_0_OR_GREATER
entity.OwnsOne(e => e.DictionaryProp, d => d.ToJson("dictionary_prop"));
#else
entity.Property(e => e.DictionaryProp).HasColumnType("jsonb");
#endif
...

Entity Model definition:
...
public Dictionary<EnumOne, string>? DictionaryProp { get; set; }
...

when I materialize any object I have the error:
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Arg_ParamName_Name'

If I change in the EntityTypeConfiguration the OwnsOne with entity.Ignore(e => e.DictionaryProp); all working so I detect that the problem is in it.
The problem before was putting the property name on ToJson becouse EFCore.NamingConventions 8.0.0-rc.2 not work well yet but I see that already are working on it.

Thanks

@roji
Copy link
Member

roji commented Nov 29, 2023

EF's ToJson support does not support arbitrary dictionaries, only strongly-typed mappings. If you need to use such a dictionary, you have to stay with the traditional Npgsql-specific POCO design. I'll update the docs to reflect this.

@roji
Copy link
Member

roji commented Nov 29, 2023

Duplicate of dotnet/efcore#29825

@roji roji marked this as a duplicate of dotnet/efcore#29825 Nov 29, 2023
@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants