You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, while using Npgsql.EntityFrameworkCore.PostgreSQL version 5.0.0, I noticed a problem when using a custom ValueConverter on a property of type enum:
publicclassBlog{publicintId{get;set;}publicBlogTypeType{get;set;}// This enum is converted using a custom ValueConverter.}publicenumBlogType{Public,// Converted to "P".Internal// Converted to "I".}// Converts the enum to a one-character string. This is just a simplified example.protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){varconverter=newValueConverter<BlogType,string>(
v =>v==BlogType.Public?"P":"I",
v =>v=="P"?BlogType.Public:BlogType.Internal);modelBuilder.Entity<Blog>().Property(e =>e.Type).HasConversion(converter);}
Given the configuration above, the problem happens when querying the blogs with .Contains() on the Type property:
varrequiredTypes=new[]{BlogType.Public,BlogType.Internal};// Must be an array to repeat the problem.varblogs=_context.Blogs.Where(b =>requiredTypes.Contains(b.Type)).ToArray();
Generated SQL query:
Executed DbCommand (11ms) [Parameters=[@__requiredTypes_0='System.String[]' (DbType = Object)], CommandType='Text']
SELECTb.id, b.typeFROM blogs AS b
WHEREb.type= ANY (@__requiredTypes_0)
Here the contents of the @__requiredTypes_0 parameter are not visible (see #1779), but the array contains the string representation of the enum values, instead of the one-character strings provided by the ValueConverter.
So the parameter contains {Public, Internal} instead of {P,I} and consequently no blog results are returned.
@Xayton thanks for reporting this - I've verified this as a bug and fixed it in #1797. Unfortunately this let into a rabbit hole with two other issues, and the whole thing is a bit much for backporting to a 5.0 patch release...
Hello, while using
Npgsql.EntityFrameworkCore.PostgreSQL
version 5.0.0, I noticed a problem when using a customValueConverter
on a property of type enum:Given the configuration above, the problem happens when querying the blogs with
.Contains()
on theType
property:Generated SQL query:
Here the contents of the
@__requiredTypes_0
parameter are not visible (see #1779), but the array contains the string representation of the enum values, instead of the one-character strings provided by theValueConverter
.So the parameter contains
{Public, Internal}
instead of{P,I}
and consequently no blog results are returned.May be related to: #1559.
Thank you.
The text was updated successfully, but these errors were encountered: