-
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 model building support for collections of owned types.
Add HasKey() to ReferenceOwnershipBuilder Add missing string overloads of OwnsOne() and HasOne() Add hiding overloads of HasData() Sort methods and fix some comments Move owned type primary key configuration to KeyDiscoveryConvention Part of #8172
- Loading branch information
1 parent
e91014d
commit f54e449
Showing
45 changed files
with
4,421 additions
and
856 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
129 changes: 129 additions & 0 deletions
129
src/EFCore.Relational/RelationalCollectionOwnershipBuilderExtensions.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,129 @@ | ||
// 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.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Relational database specific extension methods for <see cref="CollectionOwnershipBuilder" />. | ||
/// </summary> | ||
public static class RelationalCollectionOwnershipBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Configures the view or table that the entity maps to when targeting a relational database. | ||
/// </summary> | ||
/// <param name="collectionOwnershipBuilder"> The builder for the entity type being configured. </param> | ||
/// <param name="name"> The name of the view or table. </param> | ||
/// <returns> The same builder instance so that multiple calls can be chained. </returns> | ||
public static CollectionOwnershipBuilder ToTable( | ||
[NotNull] this CollectionOwnershipBuilder collectionOwnershipBuilder, | ||
[CanBeNull] string name) | ||
{ | ||
Check.NotNull(collectionOwnershipBuilder, nameof(collectionOwnershipBuilder)); | ||
Check.NullButNotEmpty(name, nameof(name)); | ||
|
||
collectionOwnershipBuilder.GetInfrastructure<InternalEntityTypeBuilder>() | ||
.Relational(ConfigurationSource.Explicit) | ||
.ToTable(name); | ||
|
||
return collectionOwnershipBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Configures the view or table that the entity maps to when targeting a relational database. | ||
/// </summary> | ||
/// <typeparam name="TEntity"> The entity type being configured. </typeparam> | ||
/// <typeparam name="TDependentEntity"> The entity type that this relationship targets. </typeparam> | ||
/// <param name="collectionOwnershipBuilder"> The builder for the entity type being configured. </param> | ||
/// <param name="name"> The name of the view or table. </param> | ||
/// <returns> The same builder instance so that multiple calls can be chained. </returns> | ||
public static CollectionOwnershipBuilder<TEntity, TDependentEntity> ToTable<TEntity, TDependentEntity>( | ||
[NotNull] this CollectionOwnershipBuilder<TEntity, TDependentEntity> collectionOwnershipBuilder, | ||
[CanBeNull] string name) | ||
where TEntity : class | ||
where TDependentEntity : class | ||
=> (CollectionOwnershipBuilder<TEntity, TDependentEntity>)ToTable((CollectionOwnershipBuilder)collectionOwnershipBuilder, name); | ||
|
||
/// <summary> | ||
/// Configures the view or table that the entity maps to when targeting a relational database. | ||
/// </summary> | ||
/// <param name="collectionOwnershipBuilder"> The builder for the entity type being configured. </param> | ||
/// <param name="name"> The name of the view or table. </param> | ||
/// <param name="schema"> The schema of the view or table. </param> | ||
/// <returns> The same builder instance so that multiple calls can be chained. </returns> | ||
public static CollectionOwnershipBuilder ToTable( | ||
[NotNull] this CollectionOwnershipBuilder collectionOwnershipBuilder, | ||
[CanBeNull] string name, | ||
[CanBeNull] string schema) | ||
{ | ||
Check.NotNull(collectionOwnershipBuilder, nameof(collectionOwnershipBuilder)); | ||
Check.NullButNotEmpty(name, nameof(name)); | ||
Check.NullButNotEmpty(schema, nameof(schema)); | ||
|
||
collectionOwnershipBuilder.GetInfrastructure<InternalEntityTypeBuilder>() | ||
.Relational(ConfigurationSource.Explicit) | ||
.ToTable(name, schema); | ||
|
||
return collectionOwnershipBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Configures the view or table that the entity maps to when targeting a relational database. | ||
/// </summary> | ||
/// <typeparam name="TEntity"> The entity type being configured. </typeparam> | ||
/// <typeparam name="TDependentEntity"> The entity type that this relationship targets. </typeparam> | ||
/// <param name="collectionOwnershipBuilder"> The builder for the entity type being configured. </param> | ||
/// <param name="name"> The name of the view or table. </param> | ||
/// <param name="schema"> The schema of the view or table. </param> | ||
/// <returns> The same builder instance so that multiple calls can be chained. </returns> | ||
public static CollectionOwnershipBuilder<TEntity, TDependentEntity> ToTable<TEntity, TDependentEntity>( | ||
[NotNull] this CollectionOwnershipBuilder<TEntity, TDependentEntity> collectionOwnershipBuilder, | ||
[CanBeNull] string name, | ||
[CanBeNull] string schema) | ||
where TEntity : class | ||
where TDependentEntity : class | ||
=> (CollectionOwnershipBuilder<TEntity, TDependentEntity>)ToTable((CollectionOwnershipBuilder)collectionOwnershipBuilder, name, schema); | ||
|
||
/// <summary> | ||
/// Configures the foreign key constraint name for this relationship when targeting a relational database. | ||
/// </summary> | ||
/// <param name="referenceReferenceBuilder"> The builder being used to configure the relationship. </param> | ||
/// <param name="name"> The name of the foreign key constraint. </param> | ||
/// <returns> The same builder instance so that multiple calls can be chained. </returns> | ||
public static CollectionOwnershipBuilder HasConstraintName( | ||
[NotNull] this CollectionOwnershipBuilder referenceReferenceBuilder, | ||
[CanBeNull] string name) | ||
{ | ||
Check.NotNull(referenceReferenceBuilder, nameof(referenceReferenceBuilder)); | ||
Check.NullButNotEmpty(name, nameof(name)); | ||
|
||
referenceReferenceBuilder.GetInfrastructure<InternalRelationshipBuilder>() | ||
.Relational(ConfigurationSource.Explicit) | ||
.HasConstraintName(name); | ||
|
||
return referenceReferenceBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Configures the foreign key constraint name for this relationship when targeting a relational database. | ||
/// </summary> | ||
/// <param name="referenceReferenceBuilder"> The builder being used to configure the relationship. </param> | ||
/// <param name="name"> The name of the foreign key constraint. </param> | ||
/// <returns> The same builder instance so that multiple calls can be chained. </returns> | ||
/// <typeparam name="TEntity"> The entity type on one end of the relationship. </typeparam> | ||
/// <typeparam name="TDependentEntity"> The entity type on the other end of the relationship. </typeparam> | ||
public static CollectionOwnershipBuilder<TEntity, TDependentEntity> HasConstraintName<TEntity, TDependentEntity>( | ||
[NotNull] this CollectionOwnershipBuilder<TEntity, TDependentEntity> referenceReferenceBuilder, | ||
[CanBeNull] string name) | ||
where TEntity : class | ||
where TDependentEntity : class | ||
=> (CollectionOwnershipBuilder<TEntity, TDependentEntity>)HasConstraintName( | ||
(CollectionOwnershipBuilder)referenceReferenceBuilder, 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
46 changes: 46 additions & 0 deletions
46
src/EFCore.SqlServer/Extensions/SqlServerCollectionOwnershipBuilderExtensions.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,46 @@ | ||
// 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.Utilities; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// SQL Server specific extension methods for <see cref="CollectionOwnershipBuilder" />. | ||
/// </summary> | ||
public static class SqlServerCollectionOwnershipBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Configures the table that the entity maps to when targeting SQL Server as memory-optimized. | ||
/// </summary> | ||
/// <param name="collectionOwnershipBuilder"> The builder for the entity type being configured. </param> | ||
/// <param name="memoryOptimized"> A value indicating whether the table is memory-optimized. </param> | ||
/// <returns> The same builder instance so that multiple calls can be chained. </returns> | ||
public static CollectionOwnershipBuilder ForSqlServerIsMemoryOptimized( | ||
[NotNull] this CollectionOwnershipBuilder collectionOwnershipBuilder, bool memoryOptimized = true) | ||
{ | ||
Check.NotNull(collectionOwnershipBuilder, nameof(collectionOwnershipBuilder)); | ||
|
||
collectionOwnershipBuilder.OwnedEntityType.SqlServer().IsMemoryOptimized = memoryOptimized; | ||
|
||
return collectionOwnershipBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Configures the table that the entity maps to when targeting SQL Server as memory-optimized. | ||
/// </summary> | ||
/// <typeparam name="TEntity"> The entity type being configured. </typeparam> | ||
/// <typeparam name="TRelatedEntity"> The entity type that this relationship targets. </typeparam> | ||
/// <param name="collectionOwnershipBuilder"> The builder for the entity type being configured. </param> | ||
/// <param name="memoryOptimized"> A value indicating whether the table is memory-optimized. </param> | ||
/// <returns> The same builder instance so that multiple calls can be chained. </returns> | ||
public static CollectionOwnershipBuilder<TEntity, TRelatedEntity> ForSqlServerIsMemoryOptimized<TEntity, TRelatedEntity>( | ||
[NotNull] this CollectionOwnershipBuilder<TEntity, TRelatedEntity> collectionOwnershipBuilder, bool memoryOptimized = true) | ||
where TEntity : class | ||
where TRelatedEntity : class | ||
=> (CollectionOwnershipBuilder<TEntity, TRelatedEntity>)ForSqlServerIsMemoryOptimized((CollectionOwnershipBuilder)collectionOwnershipBuilder, memoryOptimized); | ||
} | ||
} |
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.