-
Notifications
You must be signed in to change notification settings - Fork 255
NpgsqlOptionsExtension loses ParameterizedCollectionMode between clones #3795
Description
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.
efcore.pg/src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs
Lines 122 to 136 in 563f039
| 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.ParameterI 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