Can't map Dictionary<string,object> (e.g. to JSON) since it's detected as a property bag
See original GitHub issueWith (PostgreSQL) native JSON support, it’s useful to map Dictionary directly to JSON columns. This works e.g. for Dictionary<string,string>
, but fails for Dictionary<string,object>
since the property is detected as a property bag:
public class Blog
{
public int Id { get; set; }
[Column(TypeName = "jsonb")]
public Dictionary<string, object> JsonProperty { get; set; }
}
The exception:
The navigation 'Blog.JsonProperty' must be configured in 'OnModelCreating' with an explicit name for the target shared-type entity type, or excluded by calling 'EntityTypeBuilder.Ignore'.
We may want to stop detecting property bags if column has an explicit store type. Following on how type converters work, this can be worked around by configuring the property with .Metadata.SetProviderClrType(null)
.
/cc @AndriySvyryd
Originally filed by @ColinZeb in https://github.com/npgsql/efcore.pg/issues/2134
Issue Analytics
- State:
- Created 2 years ago
- Reactions:12
- Comments:8 (5 by maintainers)
Top Results From Across the Web
c# - Why can't property bag (Dictionary<string, object>) be ...
I have a direct reference to the document object in the loop... No you don't. You have the reference to the recipe of...
Read more >Proper JSON and property bags - ample code - WordPress.com
I recently wrote a blog post where I argued that "JSON serialization" as commonly practiced in the software industry is much too ambitious....
Read more >How to deserialize JSON to Dictionary<string, class> ...
I'm querying an API that returns a JSON dictionary in which the keys cannot be hard coded into a C# class before-hand. The...
Read more >How to enable case-insensitive property name matching ...
Learn how to enable case-insensitive property name matching while serializing to and deserializing from JSON in .NET.
Read more >Custom Dictionary JsonConverter using System.Text.Json
How to customize the deserialization/serialization of Dictionary using System.Text.Json and a custom JsonConverter.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Related to https://github.com/dotnet/efcore/issues/28871
@Mfolmer you’re definitely not supposed to be able to map a
Dictionary<string, object>
via ToJson. At this point, ToJson is only for mapping strongly-typed CLR-based entity types. We have plans to improve on that (#28871), though support is likely to take the form of JsonDocument/JsonElement support rather than via Dictionary.