-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metadata: Bring back SqlServerDbFunctionConvention
Resolve #20182
- Loading branch information
Showing
3 changed files
with
51 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/EFCore.SqlServer/Metadata/Conventions/SqlServerDbFunctionConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions | ||
{ | ||
/// <summary> | ||
/// A convention that ensures that <see cref="IDbFunction.Schema"/> is populated for database functions which are not built-in. | ||
/// </summary> | ||
public class SqlServerDbFunctionConvention : IModelFinalizingConvention | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="SqlServerDbFunctionConvention" />. | ||
/// </summary> | ||
/// <param name="dependencies"> Parameter object containing dependencies for this convention. </param> | ||
/// <param name="relationalDependencies"> Parameter object containing relational dependencies for this convention. </param> | ||
public SqlServerDbFunctionConvention( | ||
[NotNull] ProviderConventionSetBuilderDependencies dependencies, | ||
[NotNull] RelationalConventionSetBuilderDependencies relationalDependencies) | ||
{ | ||
Check.NotNull(dependencies, nameof(dependencies)); | ||
Check.NotNull(relationalDependencies, nameof(relationalDependencies)); | ||
|
||
Dependencies = dependencies; | ||
} | ||
|
||
/// <summary> | ||
/// Parameter object containing service dependencies. | ||
/// </summary> | ||
protected virtual ProviderConventionSetBuilderDependencies Dependencies { get; } | ||
|
||
/// <inheritdoc /> | ||
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context) | ||
{ | ||
foreach (var dbFunction in modelBuilder.Metadata.GetDbFunctions()) | ||
{ | ||
if (string.IsNullOrEmpty(dbFunction.Schema)) | ||
{ | ||
dbFunction.SetSchema("dbo"); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters