-
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 OwnedNavigationBuilder.HasIndex with name
Add IConventionEntityTypeBuilder API for UseSqlReturningClause and UseSqlOutputClause Fixes #33739 Fixes #33287
- Loading branch information
1 parent
def432c
commit 3279b91
Showing
20 changed files
with
493 additions
and
30 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
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
123 changes: 123 additions & 0 deletions
123
src/EFCore.Sqlite.Core/Extensions/SqliteEntityTypeBuilderExtensions.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,123 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
using Microsoft.EntityFrameworkCore.Sqlite.Metadata.Internal; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Microsoft.EntityFrameworkCore; | ||
|
||
/// <summary> | ||
/// Entity type builder extension methods for Sqlite-specific metadata. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and | ||
/// <see href="https://aka.ms/efcore-docs-sqlite">Accessing Sqlite databases with EF Core</see> for more information and examples. | ||
/// </remarks> | ||
public static class SqliteEntityTypeBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Sets a value indicating whether to use the SQL RETURNING clause when saving changes to the table. | ||
/// The RETURNING clause is incompatible with certain Sqlite features, such as virtual tables or tables with AFTER triggers. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples. | ||
/// </remarks> | ||
/// <param name="entityTypeBuilder">The builder for the entity type being configured.</param> | ||
/// <param name="useSqlReturningClause">The value to set.</param> | ||
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> | ||
/// <returns> | ||
/// The same builder instance if the configuration was applied, | ||
/// <see langword="null" /> otherwise. | ||
/// </returns> | ||
public static IConventionEntityTypeBuilder? UseSqlReturningClause( | ||
this IConventionEntityTypeBuilder entityTypeBuilder, | ||
bool? useSqlReturningClause, | ||
bool fromDataAnnotation = false) | ||
{ | ||
if (!entityTypeBuilder.CanUseSqlReturningClause(useSqlReturningClause, fromDataAnnotation)) | ||
{ | ||
return null; | ||
} | ||
|
||
entityTypeBuilder.Metadata.UseSqlReturningClause(useSqlReturningClause, fromDataAnnotation); | ||
return entityTypeBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Sets a value indicating whether to use the SQL RETURNING clause when saving changes to the table. | ||
/// The RETURNING clause is incompatible with certain Sqlite features, such as virtual tables or tables with AFTER triggers. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples. | ||
/// </remarks> | ||
/// <param name="entityTypeBuilder">The builder for the entity type being configured.</param> | ||
/// <param name="useSqlReturningClause">The value to set.</param> | ||
/// <param name="storeObject">The identifier of the table-like store object.</param> | ||
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> | ||
/// <returns> | ||
/// The same builder instance if the configuration was applied, | ||
/// <see langword="null" /> otherwise. | ||
/// </returns> | ||
public static IConventionEntityTypeBuilder? UseSqlReturningClause( | ||
this IConventionEntityTypeBuilder entityTypeBuilder, | ||
bool? useSqlReturningClause, | ||
in StoreObjectIdentifier storeObject, | ||
bool fromDataAnnotation = false) | ||
{ | ||
if (!entityTypeBuilder.CanUseSqlReturningClause(useSqlReturningClause, storeObject, fromDataAnnotation)) | ||
{ | ||
return null; | ||
} | ||
|
||
entityTypeBuilder.Metadata.UseSqlReturningClause(useSqlReturningClause, storeObject, fromDataAnnotation); | ||
return entityTypeBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Returns a value indicating whether this entity type can be configured to use the SQL RETURNING clause | ||
/// using the specified configuration source. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples. | ||
/// </remarks> | ||
/// <param name="entityTypeBuilder">The builder for the entity type being configured.</param> | ||
/// <param name="useSqlReturningClause">The value to set.</param> | ||
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> | ||
/// <returns><see langword="true" /> if the configuration can be applied.</returns> | ||
public static bool CanUseSqlReturningClause( | ||
this IConventionEntityTypeBuilder entityTypeBuilder, | ||
bool? useSqlReturningClause, | ||
bool fromDataAnnotation = false) | ||
=> entityTypeBuilder.CanSetAnnotation( | ||
SqliteAnnotationNames.UseSqlReturningClause, | ||
useSqlReturningClause, | ||
fromDataAnnotation); | ||
|
||
/// <summary> | ||
/// Returns a value indicating whether this entity type can be configured to use the SQL RETURNING clause | ||
/// using the specified configuration source. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples. | ||
/// </remarks> | ||
/// <param name="entityTypeBuilder">The builder for the entity type being configured.</param> | ||
/// <param name="useSqlReturningClause">The value to set.</param> | ||
/// <param name="storeObject">The identifier of the table-like store object.</param> | ||
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> | ||
/// <returns><see langword="true" /> if the configuration can be applied.</returns> | ||
public static bool CanUseSqlReturningClause( | ||
this IConventionEntityTypeBuilder entityTypeBuilder, | ||
bool? useSqlReturningClause, | ||
in StoreObjectIdentifier storeObject, | ||
bool fromDataAnnotation = false) | ||
=> StoreObjectIdentifier.Create(entityTypeBuilder.Metadata, storeObject.StoreObjectType) == storeObject | ||
? entityTypeBuilder.CanSetAnnotation( | ||
SqliteAnnotationNames.UseSqlReturningClause, | ||
useSqlReturningClause, | ||
fromDataAnnotation) | ||
: entityTypeBuilder.Metadata.GetOrCreateMappingFragment(storeObject, fromDataAnnotation).Builder.CanSetAnnotation( | ||
SqliteAnnotationNames.UseSqlReturningClause, | ||
useSqlReturningClause, | ||
fromDataAnnotation); | ||
} |
Oops, something went wrong.