-
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.
Query: Configure and use TypeMapping on DbFunction
- Add a convention which configures actual type mapping from store type on DbFunction - While translating db function use the TypeMapping if available Resolves #27954 Resolves #27524
- Loading branch information
Showing
5 changed files
with
137 additions
and
2 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
62 changes: 62 additions & 0 deletions
62
src/EFCore.Relational/Metadata/Conventions/ScalarDbFunctionTypeMappingConvention.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,62 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions; | ||
|
||
/// <summary> | ||
/// A convention that configures the store type to which a scalar function is mapped. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://aka.ms/efcore-docs-conventions">Model building conventions</see> and | ||
/// <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see> for more information and examples. | ||
/// </remarks> | ||
public class ScalarDbFunctionTypeMappingConvention : IModelFinalizingConvention | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="ScalarDbFunctionTypeMappingConvention" />. | ||
/// </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 ScalarDbFunctionTypeMappingConvention( | ||
ProviderConventionSetBuilderDependencies dependencies, | ||
RelationalConventionSetBuilderDependencies relationalDependencies) | ||
{ | ||
Dependencies = dependencies; | ||
RelationalDependencies = relationalDependencies; | ||
} | ||
|
||
/// <summary> | ||
/// Dependencies for this service. | ||
/// </summary> | ||
protected virtual ProviderConventionSetBuilderDependencies Dependencies { get; } | ||
|
||
/// <summary> | ||
/// Relational provider-specific dependencies for this service. | ||
/// </summary> | ||
protected virtual RelationalConventionSetBuilderDependencies RelationalDependencies { get; } | ||
|
||
/// <inheritdoc /> | ||
public virtual void ProcessModelFinalizing( | ||
IConventionModelBuilder modelBuilder, | ||
IConventionContext<IConventionModelBuilder> context) | ||
{ | ||
foreach (var function in modelBuilder.Metadata.GetDbFunctions()) | ||
{ | ||
ProcessDbFunction(function.Builder); | ||
} | ||
} | ||
|
||
private void ProcessDbFunction( | ||
IConventionDbFunctionBuilder dbFunctionBuilder) | ||
{ | ||
var function = dbFunctionBuilder.Metadata; | ||
if (!function.IsScalar | ||
|| function.StoreType == null) | ||
{ | ||
return; | ||
} | ||
|
||
var typeMapping = ((IRelationalTypeMappingSource)Dependencies.TypeMappingSource).FindMapping(function.ReturnType, function.StoreType); | ||
dbFunctionBuilder.HasTypeMapping(typeMapping); | ||
} | ||
} |
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
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
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