-
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.
Allow to ignore entity types and properties by base type or interface (…
…#25025) Allow to specify a value conversion and other facets for all properties of a given type Fixes #3867 Fixes #10784
- Loading branch information
1 parent
bd735ed
commit 4a67481
Showing
49 changed files
with
2,404 additions
and
733 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
src/EFCore.Relational/Extensions/PropertiesConfigurationBuilderExtensions.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,106 @@ | ||
// 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 Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Relational database specific extension methods for <see cref="PropertyBuilder" />. | ||
/// </summary> | ||
public static class PropertiesConfigurationBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Configures the data type of the column that the property maps to when targeting a relational database. | ||
/// This should be the complete type name, including precision, scale, length, etc. | ||
/// </summary> | ||
/// <param name="propertyBuilder"> The builder for the property being configured. </param> | ||
/// <param name="typeName"> The name of the data type of the column. </param> | ||
/// <returns> The same builder instance so that multiple calls can be chained. </returns> | ||
public static PropertiesConfigurationBuilder HaveColumnType( | ||
this PropertiesConfigurationBuilder propertyBuilder, | ||
string typeName) | ||
{ | ||
Check.NotNull(propertyBuilder, nameof(propertyBuilder)); | ||
Check.NotEmpty(typeName, nameof(typeName)); | ||
|
||
propertyBuilder.HaveAnnotation(RelationalAnnotationNames.ColumnType, typeName); | ||
|
||
return propertyBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Configures the data type of the column that the property maps to when targeting a relational database. | ||
/// This should be the complete type name, including precision, scale, length, etc. | ||
/// </summary> | ||
/// <typeparam name="TProperty"> The type of the property being configured. </typeparam> | ||
/// <param name="propertyBuilder"> The builder for the property being configured. </param> | ||
/// <param name="typeName"> The name of the data type of the column. </param> | ||
/// <returns> The same builder instance so that multiple calls can be chained. </returns> | ||
public static PropertiesConfigurationBuilder<TProperty> HaveColumnType<TProperty>( | ||
this PropertiesConfigurationBuilder<TProperty> propertyBuilder, | ||
string typeName) | ||
=> (PropertiesConfigurationBuilder<TProperty>)HaveColumnType((PropertiesConfigurationBuilder)propertyBuilder, typeName); | ||
|
||
/// <summary> | ||
/// Configures the property as capable of storing only fixed-length data, such as strings. | ||
/// </summary> | ||
/// <param name="propertyBuilder"> The builder for the property being configured. </param> | ||
/// <param name="fixedLength"> A value indicating whether the property is constrained to fixed length values. </param> | ||
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns> | ||
public static PropertiesConfigurationBuilder AreFixedLength( | ||
this PropertiesConfigurationBuilder propertyBuilder, | ||
bool fixedLength = true) | ||
{ | ||
Check.NotNull(propertyBuilder, nameof(propertyBuilder)); | ||
|
||
propertyBuilder.HaveAnnotation(RelationalAnnotationNames.IsFixedLength, fixedLength); | ||
|
||
return propertyBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Configures the property as capable of storing only fixed-length data, such as strings. | ||
/// </summary> | ||
/// <typeparam name="TProperty"> The type of the property being configured. </typeparam> | ||
/// <param name="propertyBuilder"> The builder for the property being configured. </param> | ||
/// <param name="fixedLength"> A value indicating whether the property is constrained to fixed length values. </param> | ||
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns> | ||
public static PropertiesConfigurationBuilder<TProperty> AreFixedLength<TProperty>( | ||
this PropertiesConfigurationBuilder<TProperty> propertyBuilder, | ||
bool fixedLength = true) | ||
=> (PropertiesConfigurationBuilder<TProperty>)AreFixedLength((PropertiesConfigurationBuilder)propertyBuilder, fixedLength); | ||
|
||
/// <summary> | ||
/// Configures the property to use the given collation. The database column will be created with the given | ||
/// collation, and it will be used implicitly in all collation-sensitive operations. | ||
/// </summary> | ||
/// <param name="propertyBuilder"> The builder for the property being configured. </param> | ||
/// <param name="collation"> The collation for the column. </param> | ||
/// <returns>The same builder instance so that multiple calls can be chained.</returns> | ||
public static PropertiesConfigurationBuilder UseCollation(this PropertiesConfigurationBuilder propertyBuilder, string collation) | ||
{ | ||
Check.NotNull(propertyBuilder, nameof(propertyBuilder)); | ||
Check.NotEmpty(collation, nameof(collation)); | ||
|
||
propertyBuilder.HaveAnnotation(RelationalAnnotationNames.Collation, collation); | ||
|
||
return propertyBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Configures the property to use the given collation. The database column will be created with the given | ||
/// collation, and it will be used implicitly in all collation-sensitive operations. | ||
/// </summary> | ||
/// <param name="propertyBuilder"> The builder for the property being configured. </param> | ||
/// <param name="collation"> The collation for the column. </param> | ||
/// <returns>The same builder instance so that multiple calls can be chained.</returns> | ||
public static PropertiesConfigurationBuilder<TProperty> UseCollation<TProperty>( | ||
this PropertiesConfigurationBuilder<TProperty> propertyBuilder, | ||
string collation) | ||
=> (PropertiesConfigurationBuilder<TProperty>)UseCollation((PropertiesConfigurationBuilder)propertyBuilder, collation); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/EFCore/Infrastructure/Internal/MemberInfoNameComparer.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,57 @@ | ||
// 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.Reflection; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Infrastructure.Internal | ||
{ | ||
/// <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> | ||
// Sealed for perf | ||
public sealed class MemberInfoNameComparer : IComparer<MemberInfo> | ||
{ | ||
/// <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> | ||
public static readonly MemberInfoNameComparer Instance = new(); | ||
|
||
private MemberInfoNameComparer() | ||
{ | ||
} | ||
|
||
/// <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> | ||
public int Compare(MemberInfo? x, MemberInfo? y) | ||
{ | ||
if (ReferenceEquals(x, y)) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (x is null) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (y is null) | ||
{ | ||
return 1; | ||
} | ||
|
||
return StringComparer.Ordinal.Compare(x.Name, y.Name); | ||
} | ||
} | ||
} |
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.