When calling any of the WithXyz methods on NpgsqlOptionsExtension (or corresponding methods on DbContextOptionsBuilder), the Clone method and copy-constructor lose any previous values set for ParameterizedCollectionMode.
|
public NpgsqlOptionsExtension(NpgsqlOptionsExtension copyFrom) |
|
: base(copyFrom) |
|
{ |
|
DataSource = copyFrom.DataSource; |
|
DataSourceBuilderAction = copyFrom.DataSourceBuilderAction; |
|
AdminDatabase = copyFrom.AdminDatabase; |
|
_postgresVersion = copyFrom._postgresVersion; |
|
UseRedshift = copyFrom.UseRedshift; |
|
_userRangeDefinitions = [..copyFrom._userRangeDefinitions]; |
|
_enumDefinitions = [..copyFrom._enumDefinitions]; |
|
ProvideClientCertificatesCallback = copyFrom.ProvideClientCertificatesCallback; |
|
RemoteCertificateValidationCallback = copyFrom.RemoteCertificateValidationCallback; |
|
ProvidePasswordCallback = copyFrom.ProvidePasswordCallback; |
|
ReverseNullOrdering = copyFrom.ReverseNullOrdering; |
|
} |
The base class' _parameterizedCollectionMode field is copied by the base class' copy-constructor, but the "overridden" field is not copied by NpgsqlOptionsExtension. Thus unless you call DbContextOptionsBuilder.UseParameterizedCollectionMode last you will lose the value of the field and it will always revert back to Parameter
options.UseNpgsql("connection", s => {
s.UseParameterizedCollectionMode(ParameterTranslationMode.MultipleParameters);
s.UsePostgresVersion(new Version(17,0));
});
var mode = options.Options.GetExtension<NpgsqlOptionsExtension>().ParameterizedCollectionMode; // ParameterTranslationMode.Parameter
I discovered this while writing tests against a custom IDbContextOptionsConfiguration<> that would set the mode from special configuration. I was losing the value because I was calling other builder methods after the fact. Currently we only leverage Mode=Parameter so it's not a blocking issue or anything, but I suspect the behavior is unintended
When calling any of the
WithXyzmethods onNpgsqlOptionsExtension(or corresponding methods onDbContextOptionsBuilder), theClonemethod and copy-constructor lose any previous values set forParameterizedCollectionMode.efcore.pg/src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs
Lines 122 to 136 in 563f039
The base class'
_parameterizedCollectionModefield is copied by the base class' copy-constructor, but the "overridden" field is not copied byNpgsqlOptionsExtension. Thus unless you callDbContextOptionsBuilder.UseParameterizedCollectionModelast you will lose the value of the field and it will always revert back toParameterI discovered this while writing tests against a custom
IDbContextOptionsConfiguration<>that would set the mode from special configuration. I was losing the value because I was calling other builder methods after the fact. Currently we only leverage Mode=Parameter so it's not a blocking issue or anything, but I suspect the behavior is unintended