Skip to content

Commit

Permalink
Make DbFunction.HasSchema(null) always override the attribute
Browse files Browse the repository at this point in the history
Fixes #24228
  • Loading branch information
AndriySvyryd committed Jun 3, 2021
1 parent c09204f commit b11974c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
14 changes: 5 additions & 9 deletions src/EFCore.Relational/Metadata/Internal/DbFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ public virtual string? Schema

_schema = schema;

_schemaConfigurationSource = schema == null
? (ConfigurationSource?)null
: configurationSource.Max(_schemaConfigurationSource);
_schemaConfigurationSource = configurationSource.Max(_schemaConfigurationSource);

return schema;
}
Expand Down Expand Up @@ -398,9 +396,7 @@ public virtual string Name

_name = name;

_nameConfigurationSource = name == null
? (ConfigurationSource?)null
: configurationSource.Max(_nameConfigurationSource);
_nameConfigurationSource = configurationSource.Max(_nameConfigurationSource);

return name;
}
Expand Down Expand Up @@ -518,7 +514,7 @@ public virtual string? StoreType
_storeType = storeType;

_storeTypeConfigurationSource = storeType == null
? (ConfigurationSource?)null
? null
: configurationSource.Max(_storeTypeConfigurationSource);

return storeType;
Expand Down Expand Up @@ -567,7 +563,7 @@ public virtual RelationalTypeMapping? TypeMapping
_typeMapping = typeMapping;

_typeMappingConfigurationSource = typeMapping == null
? (ConfigurationSource?)null
? null
: configurationSource.Max(_typeMappingConfigurationSource);

return typeMapping;
Expand Down Expand Up @@ -615,7 +611,7 @@ public virtual Func<IReadOnlyList<SqlExpression>, SqlExpression>? Translation
_translation = translation;

_translationConfigurationSource = translation == null
? (ConfigurationSource?)null
? null
: configurationSource.Max(_translationConfigurationSource);

return translation;
Expand Down
31 changes: 19 additions & 12 deletions test/EFCore.Relational.Tests/Metadata/DbFunctionMetadataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -869,11 +882,5 @@ public void DbFunction_Queryable_custom_translation()

private TestHelpers.TestModelBuilder GetModelBuilder()
=> RelationalTestHelpers.Instance.CreateConventionBuilder();

private ProviderConventionSetBuilderDependencies CreateDependencies()
=> RelationalTestHelpers.Instance.CreateContextServices().GetRequiredService<ProviderConventionSetBuilderDependencies>();

private RelationalConventionSetBuilderDependencies CreateRelationalDependencies()
=> RelationalTestHelpers.Instance.CreateContextServices().GetRequiredService<RelationalConventionSetBuilderDependencies>();
}
}

0 comments on commit b11974c

Please sign in to comment.