// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using EntityFrameworkCore.Jet.Metadata;
using EntityFrameworkCore.Jet.Metadata.Internal;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
public static class JetModelExtensions
{
///
/// Returns the default identity seed.
///
/// The model.
/// The default identity seed.
public static int GetIdentitySeed([NotNull] this IReadOnlyModel model)
=> (int?) model[JetAnnotationNames.IdentitySeed] ?? 1;
///
/// Sets the default identity seed.
///
/// The model.
/// The value to set.
public static void SetIdentitySeed([NotNull] this IMutableModel model, int? seed)
=> model.SetOrRemoveAnnotation(
JetAnnotationNames.IdentitySeed,
seed);
///
/// Sets the default identity seed.
///
/// The model.
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
public static void SetIdentitySeed([NotNull] this IConventionModel model, int? seed, bool fromDataAnnotation = false)
=> model.SetOrRemoveAnnotation(
JetAnnotationNames.IdentitySeed,
seed,
fromDataAnnotation);
///
/// Returns the for the default schema.
///
/// The model.
/// The for the default schema.
public static ConfigurationSource? GetIdentitySeedConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(JetAnnotationNames.IdentitySeed)?.GetConfigurationSource();
///
/// Returns the default identity increment.
///
/// The model.
/// The default identity increment.
public static int GetIdentityIncrement([NotNull] this IReadOnlyModel model)
=> (int?) model[JetAnnotationNames.IdentityIncrement] ?? 1;
///
/// Sets the default identity increment.
///
/// The model.
/// The value to set.
public static void SetIdentityIncrement([NotNull] this IMutableModel model, int? increment)
=> model.SetOrRemoveAnnotation(
JetAnnotationNames.IdentityIncrement,
increment);
///
/// Sets the default identity increment.
///
/// The model.
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
public static void SetIdentityIncrement(
[NotNull] this IConventionModel model, int? increment, bool fromDataAnnotation = false)
=> model.SetOrRemoveAnnotation(
JetAnnotationNames.IdentityIncrement,
increment,
fromDataAnnotation);
///
/// Returns the for the default identity increment.
///
/// The model.
/// The for the default identity increment.
public static ConfigurationSource? GetIdentityIncrementConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(JetAnnotationNames.IdentityIncrement)?.GetConfigurationSource();
///
/// Returns the to use for properties
/// of keys in the model, unless the property has a strategy explicitly set.
///
/// The model.
/// The default .
public static JetValueGenerationStrategy? GetValueGenerationStrategy([NotNull] this IReadOnlyModel model)
=> (JetValueGenerationStrategy?) model[JetAnnotationNames.ValueGenerationStrategy];
///
/// Sets the to use for properties
/// of keys in the model that don't have a strategy explicitly set.
///
/// The model.
/// The value to set.
public static void SetValueGenerationStrategy([NotNull] this IMutableModel model, JetValueGenerationStrategy? value)
=> model.SetOrRemoveAnnotation(JetAnnotationNames.ValueGenerationStrategy, value);
///
/// Sets the to use for properties
/// of keys in the model that don't have a strategy explicitly set.
///
/// The model.
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
public static void SetValueGenerationStrategy(
[NotNull] this IConventionModel model, JetValueGenerationStrategy? value, bool fromDataAnnotation = false)
=> model.SetOrRemoveAnnotation(JetAnnotationNames.ValueGenerationStrategy, value, fromDataAnnotation);
///
/// Returns the for the default .
///
/// The model.
/// The for the default .
public static ConfigurationSource? GetValueGenerationStrategyConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(JetAnnotationNames.ValueGenerationStrategy)?.GetConfigurationSource();
}
}