Revert ca0feb49 . Same name extensions when using sql server and jet

7.0-servicing
Christopher Jolly 3 years ago
parent 84e40f5085
commit fd6c2aec01

@ -1,393 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Linq;
using EntityFrameworkCore.Jet.Metadata.Internal;
using EntityFrameworkCore.Jet.Utilities;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
#nullable enable
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
/// <summary>
/// Extension methods for <see cref="IndexBuilder" /> for Jet-specific metadata.
/// </summary>
public static class JetIndexBuilderExtensions
{
/// <summary>
/// Configures whether the index is clustered when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="clustered">A value indicating whether the index is clustered.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder IsClustered(this IndexBuilder indexBuilder, bool clustered = false)
{
indexBuilder.Metadata.SetIsClustered(clustered);
return indexBuilder;
}
/// <summary>
/// Configures whether the index is clustered when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="clustered">A value indicating whether the index is clustered.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> IsClustered<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
bool clustered = false)
=> (IndexBuilder<TEntity>)IsClustered((IndexBuilder)indexBuilder, clustered);
/// <summary>
/// Configures whether the index is clustered when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="clustered">A value indicating whether the index is clustered.</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 IConventionIndexBuilder? IsClustered(
this IConventionIndexBuilder indexBuilder,
bool? clustered,
bool fromDataAnnotation = false)
{
if (indexBuilder.CanSetIsClustered(clustered, fromDataAnnotation))
{
indexBuilder.Metadata.SetIsClustered(clustered, fromDataAnnotation);
return indexBuilder;
}
return null;
}
/// <summary>
/// Returns a value indicating whether the index can be configured as clustered.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="clustered">A value indicating whether the index is clustered.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns><see langword="true" /> if the index can be configured as clustered.</returns>
public static bool CanSetIsClustered(
this IConventionIndexBuilder indexBuilder,
bool? clustered,
bool fromDataAnnotation = false)
=> false;
/// <summary>
/// Configures index include properties when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="propertyNames">An array of property names to be used in 'include' clause.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder IncludeProperties(this IndexBuilder indexBuilder, params string[] propertyNames)
{
Check.NotNull(propertyNames, nameof(propertyNames));
indexBuilder.Metadata.SetIncludeProperties(propertyNames);
return indexBuilder;
}
/// <summary>
/// Configures index include properties when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="propertyNames">An array of property names to be used in 'include' clause.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> IncludeProperties<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
params string[] propertyNames)
{
Check.NotNull(propertyNames, nameof(propertyNames));
indexBuilder.Metadata.SetIncludeProperties(propertyNames);
return indexBuilder;
}
/// <summary>
/// Configures index include properties when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="includeExpression">
/// <para>
/// A lambda expression representing the property(s) to be included in the 'include' clause
/// (<c>blog => blog.Url</c>).
/// </para>
/// <para>
/// If multiple properties are to be included then specify an anonymous type including the
/// properties (<c>post => new { post.Title, post.BlogId }</c>).
/// </para>
/// </param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> IncludeProperties<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
Expression<Func<TEntity, object?>> includeExpression)
{
Check.NotNull(includeExpression, nameof(includeExpression));
//IncludeProperties(
// indexBuilder,
// includeExpression.GetMemberAccessList().Select(EntityFrameworkMemberInfoExtensions.GetSimpleMemberName).ToArray());
return indexBuilder;
}
/// <summary>
/// Configures index include properties when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="propertyNames">An array of property names to be used in 'include' clause.</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 IConventionIndexBuilder? IncludeProperties(
this IConventionIndexBuilder indexBuilder,
IReadOnlyList<string> propertyNames,
bool fromDataAnnotation = false)
{
if (indexBuilder.CanSetIncludeProperties(propertyNames, fromDataAnnotation))
{
indexBuilder.Metadata.SetIncludeProperties(propertyNames, fromDataAnnotation);
return indexBuilder;
}
return null;
}
/// <summary>
/// Returns a value indicating whether the given include properties can be set.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="propertyNames">An array of property names to be used in 'include' clause.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns><see langword="true" /> if the given include properties can be set.</returns>
public static bool CanSetIncludeProperties(
this IConventionIndexBuilder indexBuilder,
IReadOnlyList<string>? propertyNames,
bool fromDataAnnotation = false)
=> false;
/// <summary>
/// Configures whether the index is created with online option when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="createdOnline">A value indicating whether the index is created with online option.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder IsCreatedOnline(this IndexBuilder indexBuilder, bool createdOnline = true)
{
//indexBuilder.Metadata.SetIsCreatedOnline(createdOnline);
return indexBuilder;
}
/// <summary>
/// Configures whether the index is created with online option when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="createdOnline">A value indicating whether the index is created with online option.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> IsCreatedOnline<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
bool createdOnline = true)
=> (IndexBuilder<TEntity>)IsCreatedOnline((IndexBuilder)indexBuilder, createdOnline);
/// <summary>
/// Configures whether the index is created with online option when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="createdOnline">A value indicating whether the index is created with online option.</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 IConventionIndexBuilder? IsCreatedOnline(
this IConventionIndexBuilder indexBuilder,
bool? createdOnline,
bool fromDataAnnotation = false)
{
if (indexBuilder.CanSetIsCreatedOnline(createdOnline, fromDataAnnotation))
{
//indexBuilder.Metadata.SetIsCreatedOnline(createdOnline, fromDataAnnotation);
return indexBuilder;
}
return null;
}
/// <summary>
/// Returns a value indicating whether the index can be configured with online option when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="createdOnline">A value indicating whether the index is created with online option.</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>
/// <returns><see langword="true" /> if the index can be configured with online option when targeting SQL Server.</returns>
public static bool CanSetIsCreatedOnline(
this IConventionIndexBuilder indexBuilder,
bool? createdOnline,
bool fromDataAnnotation = false)
=> false;
/// <summary>
/// Configures whether the index is created with fill factor option when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="fillFactor">A value indicating whether the index is created with fill factor option.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder HasFillFactor(this IndexBuilder indexBuilder, int fillFactor)
{
//indexBuilder.Metadata.SetFillFactor(fillFactor);
return indexBuilder;
}
/// <summary>
/// Configures whether the index is created with fill factor option when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="fillFactor">A value indicating whether the index is created with fill factor option.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> HasFillFactor<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
int fillFactor)
=> (IndexBuilder<TEntity>)HasFillFactor((IndexBuilder)indexBuilder, fillFactor);
/// <summary>
/// Configures whether the index is created with fill factor option when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="fillFactor">A value indicating whether the index is created with fill factor option.</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 IConventionIndexBuilder? HasFillFactor(
this IConventionIndexBuilder indexBuilder,
int? fillFactor,
bool fromDataAnnotation = false)
{
if (indexBuilder.CanSetFillFactor(fillFactor, fromDataAnnotation))
{
//indexBuilder.Metadata.SetFillFactor(fillFactor, fromDataAnnotation);
return indexBuilder;
}
return null;
}
/// <summary>
/// Returns a value indicating whether the index can be configured with fill factor option when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="fillFactor">A value indicating whether the index is created with fill factor option.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns><see langword="true" /> if the index can be configured with fill factor option when targeting SQL Server.</returns>
public static bool CanSetFillFactor(
this IConventionIndexBuilder indexBuilder,
int? fillFactor,
bool fromDataAnnotation = false)
=> false;
}
}

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using EntityFrameworkCore.Jet.Metadata.Internal;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
// ReSharper disable once CheckNamespace
@ -13,73 +11,6 @@ namespace Microsoft.EntityFrameworkCore
/// </summary>
public static class JetIndexExtensions
{
/// <summary>
/// Returns a value indicating whether the index is clustered.
/// </summary>
/// <param name="index">The index.</param>
/// <returns><see langword="true" /> if the index is clustered.</returns>
public static bool? IsClustered(this IReadOnlyIndex index)
=> (index is RuntimeIndex)
? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)
: (bool?)index[JetAnnotationNames.Clustered];
/// <summary>
/// Returns a value indicating whether the index is clustered.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="storeObject">The identifier of the store object.</param>
/// <returns><see langword="true" /> if the index is clustered.</returns>
public static bool? IsClustered(this IReadOnlyIndex index, in StoreObjectIdentifier storeObject)
{
if (index is RuntimeIndex)
{
throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData);
}
var annotation = index.FindAnnotation(JetAnnotationNames.Clustered);
if (annotation != null)
{
return (bool?)annotation.Value;
}
var sharedTableRootIndex = index.FindSharedObjectRootIndex(storeObject);
return sharedTableRootIndex?.IsClustered(storeObject);
}
/// <summary>
/// Sets a value indicating whether the index is clustered.
/// </summary>
/// <param name="value">The value to set.</param>
/// <param name="index">The index.</param>
public static void SetIsClustered(this IMutableIndex index, bool? value)
=> index.SetAnnotation(
JetAnnotationNames.Clustered,
value);
/// <summary>
/// Sets a value indicating whether the index is clustered.
/// </summary>
/// <param name="value">The value to set.</param>
/// <param name="index">The index.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static bool? SetIsClustered(
this IConventionIndex index,
bool? value,
bool fromDataAnnotation = false)
=> (bool?)index.SetAnnotation(
JetAnnotationNames.Clustered,
value,
fromDataAnnotation)?.Value;
/// <summary>
/// Returns the <see cref="ConfigurationSource" /> for whether the index is clustered.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>The <see cref="ConfigurationSource" /> for whether the index is clustered.</returns>
public static ConfigurationSource? GetIsClusteredConfigurationSource(this IConventionIndex property)
=> property.FindAnnotation(JetAnnotationNames.Clustered)?.GetConfigurationSource();
/// <summary>
/// Returns included property names, or <c>null</c> if they have not been specified.
/// </summary>

@ -1,101 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Linq;
using EntityFrameworkCore.Jet.Metadata.Internal;
using EntityFrameworkCore.Jet.Utilities;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
#nullable enable
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
/// <summary>
/// Extension methods for <see cref="KeyBuilder" /> for Jet-specific metadata.
/// </summary>
public static class JetKeyBuilderExtensions
{
/// <summary>
/// Configures whether the key is clustered when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="keyBuilder">The builder for the key being configured.</param>
/// <param name="clustered">A value indicating whether the key is clustered.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static KeyBuilder IsClustered(this KeyBuilder keyBuilder, bool clustered = true)
{
keyBuilder.Metadata.SetIsClustered(clustered);
return keyBuilder;
}
/// <summary>
/// Configures whether the key is clustered when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="keyBuilder">The builder for the key being configured.</param>
/// <param name="clustered">A value indicating whether the key is clustered.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static KeyBuilder<TEntity> IsClustered<TEntity>(
this KeyBuilder<TEntity> keyBuilder,
bool clustered = true)
=> (KeyBuilder<TEntity>)IsClustered((KeyBuilder)keyBuilder, clustered);
/// <summary>
/// Configures whether the key is clustered when targeting SQL Server.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="keyBuilder">The builder for the key being configured.</param>
/// <param name="clustered">A value indicating whether the key is clustered.</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 IConventionKeyBuilder? IsClustered(
this IConventionKeyBuilder keyBuilder,
bool? clustered,
bool fromDataAnnotation = false)
{
if (keyBuilder.CanSetIsClustered(clustered, fromDataAnnotation))
{
keyBuilder.Metadata.SetIsClustered(clustered, fromDataAnnotation);
return keyBuilder;
}
return null;
}
/// <summary>
/// Returns a value indicating whether the key can be configured as clustered.
/// </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-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
/// for more information and examples.
/// </remarks>
/// <param name="keyBuilder">The builder for the key being configured.</param>
/// <param name="clustered">A value indicating whether the key is clustered.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns><see langword="true" /> if the key can be configured as clustered.</returns>
public static bool CanSetIsClustered(
this IConventionKeyBuilder keyBuilder,
bool? clustered,
bool fromDataAnnotation = false)
=> keyBuilder.CanSetAnnotation(JetAnnotationNames.Clustered, clustered, fromDataAnnotation);
}
}

@ -1,83 +0,0 @@
using System;
using System.Collections.Generic;
using EntityFrameworkCore.Jet.Metadata.Internal;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
/// <summary>
/// Key extension methods for SQL Server-specific metadata.
/// </summary>
public static class JetKeyExtensions
{
/// <summary>
/// Returns a value indicating whether the key is clustered.
/// </summary>
/// <param name="key">The key.</param>
/// <returns><see langword="true" /> if the key is clustered.</returns>
public static bool? IsClustered(this IReadOnlyKey key)
=> (key is RuntimeKey)
? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)
: (bool?)key[JetAnnotationNames.Clustered];
/// <summary>
/// Returns a value indicating whether the key is clustered.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="storeObject">The identifier of the store object.</param>
/// <returns><see langword="true" /> if the key is clustered.</returns>
public static bool? IsClustered(this IReadOnlyKey key, in StoreObjectIdentifier storeObject)
{
if (key is RuntimeKey)
{
throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData);
}
var annotation = key.FindAnnotation(JetAnnotationNames.Clustered);
if (annotation != null)
{
return (bool?)annotation.Value;
}
return GetDefaultIsClustered(key, storeObject);
}
private static bool? GetDefaultIsClustered(IReadOnlyKey key, in StoreObjectIdentifier storeObject)
{
var sharedTableRootKey = key.FindSharedObjectRootKey(storeObject);
return sharedTableRootKey?.IsClustered(storeObject);
}
/// <summary>
/// Sets a value indicating whether the key is clustered.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="clustered">The value to set.</param>
public static void SetIsClustered(this IMutableKey key, bool? clustered)
=> key.SetOrRemoveAnnotation(JetAnnotationNames.Clustered, clustered);
/// <summary>
/// Sets a value indicating whether the key is clustered.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="clustered">The value to set.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static bool? SetIsClustered(this IConventionKey key, bool? clustered, bool fromDataAnnotation = false)
=> (bool?)key.SetOrRemoveAnnotation(
JetAnnotationNames.Clustered,
clustered,
fromDataAnnotation)?.Value;
/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for whether the key is clustered.
/// </summary>
/// <param name="key">The key.</param>
/// <returns>The <see cref="ConfigurationSource" /> for whether the key is clustered.</returns>
public static ConfigurationSource? GetIsClusteredConfigurationSource(this IConventionKey key)
=> key.FindAnnotation(JetAnnotationNames.Clustered)?.GetConfigurationSource();
}
}

@ -18,14 +18,6 @@ namespace EntityFrameworkCore.Jet.Metadata.Internal
/// </summary>
public const string Prefix = "Jet:";
/// <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 const string Clustered = Prefix + "Clustered";
/// <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

Loading…
Cancel
Save