Skip to content

Can't map Dictionary<string,object> (e.g. to JSON) since it's detected as a property bag #26903

@roji

Description

@roji

With (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 npgsql/efcore.pg#2134

Metadata

Metadata

Assignees

Labels

area-model-buildingcustomer-reportedpriority-bugIssues which requires API breaks and have bigger impact hence should be fixed earlier in the release

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions