Entity Framework Core Custom Enum Key Dictionary Converter implementation

상준 이 251 Reputation points
2021-10-12T08:47:13.133+00:00

I made an SDK that uses Cosmos DB via EF Core.
I created a Service by accessing Cosmos DB from the SDK,
I used this Service in Isolate Azure Timer Trigger. Then the following error occurred.

The Property {property} is a collection or enumeration type with a value converter but with no value comparer. Set a value comparer to ensure the collection/enumeration elements are compared correctly.

The above warning was not left by me, it was launched by Azure Function. No exceptions were thrown, the code worked all the way to the end, and the data entered Cosmos DB properly.

After searching and searching, it seems that a converter must be specified for the Enum value through HasConversion in the EF Core Context.
My code is below.

   modelBuilder.Entity<Qoo10JpCategory>()  
               .Property(e => e.CATE_S_NM)  
               .HasConversion(  
                   v => JsonConvert.SerializeObject(v),  
                   v => JsonConvert.DeserializeObject<Dictionary<ELanguage, string>>(v));  

ELanguage is an Enum type.
There is a thing called 'EnumToStringConverter', but this is for converting Enum to String, and this doesn't seem to be used when Enum is used as a key in Dictionary.
The data is corrected correctly, but I can't ignore these warnings.
How can I define an EF Core ValueConverter when using Enum as Key in Dictionary? Or is there something already defined?

Please Reply. Thanks.

139738-image.png

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
697 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,249 questions
0 comments No comments
{count} votes