'EF Core Value Converter Usage: Type vs Instance
I have a simple value converter (ValueConverter<List<string>, string>) for a property. The code is not important, but it turns a semicolon delimited list of strings into a string array. I want to apply it to a List<string> property so that my colon-delimited database-stored column can be turned into an array of strings in .NET.
If I apply it like this, it works:
builder.Property(x => x.Pictures)
.HasColumnName("Pictures")
.HasColumnType("nvarchar(max)")
.HasConversion(new SemicolonValuesConverter());
But if I apply it like this, it doesn't:
builder.Property(x => x.Pictures)
.HasColumnName("Pictures")
.HasColumnType("nvarchar(max)")
.HasConversion<SemicolonValuesConverter>();
Class SemicolonValuesConverter is public, has a public parameterless constructor and inherits from ValueConverter<List<string>, string>. As I said, it works just fine if I pass an instance, but not if I pass the type.
The error I get is:
System.InvalidOperationException: The property 'Venue.Pictures' is of type 'List< string >' which is not supported by the current database provider. Either change the property CLR type, or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
