Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DbFunction.HasSchema(null) always override the attribute #25031

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>();
}
}