npgsql / efcore.pg

Entity Framework Core provider for PostgreSQL
PostgreSQL License
1.52k stars 223 forks source link

The type mapping for 'Dictionary<string, string>' has not implemented code literal generation. #1318

Open mijgame opened 4 years ago

mijgame commented 4 years ago

Hi,

I have a model as follows:

    public class JobDefinition
    {
        [Required]
        public Guid JobDefinitionId { get; set; }

        [Required]
        public int Version { get; set; }

        [Required]
        public Guid TenantId { get; set; }

        [Required]
        public JobType JobType { get; set; }

        [Required]
        public string ActionType { get; set; }

        [Required]
        [Column(TypeName="jsob")]
        public Dictionary<string, string> Properties { get; set; }

        // Refers to another entity
        public List<ScheduleJobDefinitions> ScheduleJobDefinitions { get; set; }
    }

If I understand correctly, this should work and convert the dictionary to a json object. When generating the migration using dotnet ef migrations add DbInitial -o Database/Migrations, the program builds but then gives the following error: The type mapping for 'Dictionary<string, string>' has not implemented code literal generation.

What could be going on? I have also tried [Column(TypeName="hstore")], but that didn't make a difference unfortunately.

I use .NET Core 3.1.2 with Entity Framework Core.

Thanks in advance.

roji commented 4 years ago

You're probably trying to seed hstore data (with the HasData API). Unfortunately that's not possible currently - I'll keep this open and will try to look into it at some point.

mijgame commented 4 years ago

That is exactly what is happening; thanks for pointing me into the right direction!

roji commented 2 years ago

This should be unblocked by https://github.com/dotnet/efcore/pull/28330, implement this mainly to verify that.