diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs index 74f557489ba..482db686a45 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs @@ -356,9 +356,7 @@ public virtual string? Schema _schema = schema; - _schemaConfigurationSource = schema == null - ? (ConfigurationSource?)null - : configurationSource.Max(_schemaConfigurationSource); + _schemaConfigurationSource = configurationSource.Max(_schemaConfigurationSource); return schema; } @@ -398,9 +396,7 @@ public virtual string Name _name = name; - _nameConfigurationSource = name == null - ? (ConfigurationSource?)null - : configurationSource.Max(_nameConfigurationSource); + _nameConfigurationSource = configurationSource.Max(_nameConfigurationSource); return name; } @@ -518,7 +514,7 @@ public virtual string? StoreType _storeType = storeType; _storeTypeConfigurationSource = storeType == null - ? (ConfigurationSource?)null + ? null : configurationSource.Max(_storeTypeConfigurationSource); return storeType; @@ -567,7 +563,7 @@ public virtual RelationalTypeMapping? TypeMapping _typeMapping = typeMapping; _typeMappingConfigurationSource = typeMapping == null - ? (ConfigurationSource?)null + ? null : configurationSource.Max(_typeMappingConfigurationSource); return typeMapping; @@ -615,7 +611,7 @@ public virtual Func, SqlExpression>? Translation _translation = translation; _translationConfigurationSource = translation == null - ? (ConfigurationSource?)null + ? null : configurationSource.Max(_translationConfigurationSource); return translation; diff --git a/test/EFCore.Relational.Tests/Metadata/DbFunctionMetadataTests.cs b/test/EFCore.Relational.Tests/Metadata/DbFunctionMetadataTests.cs index 7f548230123..47e26150e71 100644 --- a/test/EFCore.Relational.Tests/Metadata/DbFunctionMetadataTests.cs +++ b/test/EFCore.Relational.Tests/Metadata/DbFunctionMetadataTests.cs @@ -506,15 +506,21 @@ public void Adding_method_with_attribute_and_fluent_api_configuration_source() var modelBuilder = GetModelBuilder(); var dbFuncBuilder = modelBuilder.HasDbFunction(MethodBmi) - .HasName("foo") - .HasSchema("bar"); + .HasName(null) + .HasSchema(null); var dbFunc = dbFuncBuilder.Metadata; + Assert.Equal(MethodBmi.Name, dbFunc.Name); + Assert.Null(dbFunc.Schema); + + dbFuncBuilder.HasName("foo"); + dbFuncBuilder.HasSchema("BAR"); + modelBuilder.FinalizeModel(); Assert.Equal("foo", dbFunc.Name); - Assert.Equal("bar", dbFunc.Schema); + Assert.Equal("BAR", dbFunc.Schema); Assert.Equal(typeof(int), dbFunc.MethodInfo.ReturnType); } @@ -523,14 +529,21 @@ public void Adding_method_with_attribute_and_fluent_configuration_source() { var modelBuilder = GetModelBuilder(); - modelBuilder.HasDbFunction(MethodBmi, funcBuilder => funcBuilder.HasName("foo").HasSchema("bar")); + modelBuilder.HasDbFunction(MethodBmi, funcBuilder => funcBuilder.HasName(null).HasSchema(null)); + + var dbFuncBuilder = modelBuilder.HasDbFunction(MethodBmi); + var dbFunc = dbFuncBuilder.Metadata; + + Assert.Equal(MethodBmi.Name, dbFunc.Name); + Assert.Null(dbFunc.Schema); - var dbFunc = modelBuilder.HasDbFunction(MethodBmi).Metadata; + dbFuncBuilder.HasName("foo"); + dbFuncBuilder.HasSchema("BAR"); modelBuilder.FinalizeModel(); Assert.Equal("foo", dbFunc.Name); - Assert.Equal("bar", dbFunc.Schema); + Assert.Equal("BAR", dbFunc.Schema); Assert.Equal(typeof(int), dbFunc.MethodInfo.ReturnType); } @@ -869,11 +882,5 @@ public void DbFunction_Queryable_custom_translation() private TestHelpers.TestModelBuilder GetModelBuilder() => RelationalTestHelpers.Instance.CreateConventionBuilder(); - - private ProviderConventionSetBuilderDependencies CreateDependencies() - => RelationalTestHelpers.Instance.CreateContextServices().GetRequiredService(); - - private RelationalConventionSetBuilderDependencies CreateRelationalDependencies() - => RelationalTestHelpers.Instance.CreateContextServices().GetRequiredService(); } }