-
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.
Add DbFunctionParameter support for DbFunctions
- Loading branch information
1 parent
d48ceef
commit c2c05fc
Showing
21 changed files
with
912 additions
and
71 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
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
150 changes: 150 additions & 0 deletions
150
src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.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,150 @@ | ||
// 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 System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Text; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata.Builders | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Provides a simple API for configuring a <see cref="DbFunctionParameter" />. | ||
/// </para> | ||
/// <para> | ||
/// Instances of this class are returned from methods when using the <see cref="ModelBuilder" /> API | ||
/// and it is not designed to be directly constructed in your application code. | ||
/// </para> | ||
/// </summary> | ||
public class DbFunctionParameterBuilder : IConventionDbFunctionParameterBuilder | ||
{ | ||
private readonly DbFunctionParameter _parameter; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
[EntityFrameworkInternal] | ||
public DbFunctionParameterBuilder([NotNull] IMutableDbFunctionParameter parameter) | ||
{ | ||
Check.NotNull(parameter, nameof(parameter)); | ||
|
||
_parameter = (DbFunctionParameter)parameter; | ||
} | ||
|
||
public virtual IMutableDbFunctionParameter Metadata => _parameter; | ||
|
||
/// <inheritdoc /> | ||
IConventionDbFunctionParameter IConventionDbFunctionParameterBuilder.Metadata => _parameter; | ||
|
||
/// <summary> | ||
/// Specify if this parameter supports Nullability Propagation | ||
/// </summary> | ||
public virtual DbFunctionParameterBuilder HasNullabilityPropagation(bool supportsNullabilityPropagation) | ||
{ | ||
_parameter.SupportsNullPropagation = supportsNullabilityPropagation; | ||
|
||
return this; | ||
} | ||
|
||
IConventionDbFunctionParameterBuilder IConventionDbFunctionParameterBuilder.HasNullPropagation( | ||
bool supportsNullPropagation, bool fromDataAnnotation) | ||
{ | ||
if (((IConventionDbFunctionParameterBuilder)this).CanSetSupportsNullPropagation(supportsNullPropagation, fromDataAnnotation)) | ||
{ | ||
((IConventionDbFunctionParameter)_parameter).SetSupportsNullPropagation(supportsNullPropagation, fromDataAnnotation); | ||
return this; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
bool IConventionDbFunctionParameterBuilder.CanSetSupportsNullPropagation(bool supportsNullPropagation, bool fromDataAnnotation) | ||
{ | ||
return Overrides(fromDataAnnotation, _parameter.GetSupportsNullPropagationConfigurationSource()) | ||
|| _parameter.SupportsNullPropagation == supportsNullPropagation; | ||
} | ||
|
||
public virtual DbFunctionParameterBuilder HasStoreType([CanBeNull] string storeType) | ||
{ | ||
_parameter.StoreType = storeType; | ||
|
||
return this; | ||
} | ||
|
||
IConventionDbFunctionParameterBuilder IConventionDbFunctionParameterBuilder.HasStoreType(string storeType, bool fromDataAnnotation) | ||
{ | ||
if (((IConventionDbFunctionParameterBuilder)this).CanSetStoreType(storeType, fromDataAnnotation)) | ||
{ | ||
((IConventionDbFunctionParameter)_parameter).SetStoreType(storeType, fromDataAnnotation); | ||
return this; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
bool IConventionDbFunctionParameterBuilder.CanSetStoreType(string storeType, bool fromDataAnnotation) | ||
{ | ||
return Overrides(fromDataAnnotation, _parameter.GetStoreTypeConfigurationSource()) | ||
|| _parameter.StoreType == storeType; | ||
} | ||
|
||
IConventionDbFunctionParameterBuilder IConventionDbFunctionParameterBuilder.HasTypeMapping( | ||
RelationalTypeMapping typeMapping, bool fromDataAnnotation) | ||
{ | ||
if (((IConventionDbFunctionParameterBuilder)this).CanSetTypeMapping(typeMapping, fromDataAnnotation)) | ||
{ | ||
((IConventionDbFunctionParameter)_parameter).SetTypeMapping(typeMapping, fromDataAnnotation); | ||
return this; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
bool IConventionDbFunctionParameterBuilder.CanSetTypeMapping(RelationalTypeMapping typeMapping, bool fromDataAnnotation) | ||
{ | ||
return Overrides(fromDataAnnotation, _parameter.GetTypeMappingConfigurationSource()) | ||
|| _parameter.TypeMapping == typeMapping; | ||
} | ||
|
||
private bool Overrides(bool fromDataAnnotation, ConfigurationSource? configurationSource) | ||
=> (fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention) | ||
.Overrides(configurationSource); | ||
|
||
#region Hidden System.Object members | ||
|
||
/// <summary> | ||
/// Returns a string that represents the current object. | ||
/// </summary> | ||
/// <returns> A string that represents the current object. </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override string ToString() => base.ToString(); | ||
|
||
/// <summary> | ||
/// Determines whether the specified object is equal to the current object. | ||
/// </summary> | ||
/// <param name="obj"> The object to compare with the current object. </param> | ||
/// <returns> true if the specified object is equal to the current object; otherwise, false. </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
// ReSharper disable once BaseObjectEqualsIsObjectEquals | ||
public override bool Equals(object obj) => base.Equals(obj); | ||
|
||
/// <summary> | ||
/// Serves as the default hash function. | ||
/// </summary> | ||
/// <returns> A hash code for the current object. </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
// ReSharper disable once BaseObjectGetHashCodeCallInGetHashCode | ||
public override int GetHashCode() => base.GetHashCode(); | ||
|
||
#endregion | ||
} | ||
} |
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
Oops, something went wrong.