private Exception CreateDuplicateItemException( T entity, IUniqueConstraint <T> constraint) { string message = constraint.FormatMessage(entity); return(new DuplicateItemException(message)); }
public static string ToDebugString( [NotNull] this IUniqueConstraint uniqueConstraint, MetadataDebugStringOptions options, int indent = 0) { var builder = new StringBuilder(); var indentString = new string(' ', indent); builder.Append(indentString); var singleLine = (options & MetadataDebugStringOptions.SingleLine) != 0; if (singleLine) { builder.Append("Key: "); } builder .Append(uniqueConstraint.Name) .Append(" ") .Append(ColumnBase.Format(uniqueConstraint.Columns)); if (uniqueConstraint.GetIsPrimaryKey()) { builder.Append(" PrimaryKey"); } if (!singleLine && (options & MetadataDebugStringOptions.IncludeAnnotations) != 0) { builder.Append(uniqueConstraint.AnnotationsToDebugString(indent + 2)); } return(builder.ToString()); }
public static void ReportError <T, TProperty>( T entity, LocatedRef <TProperty> value, IDiagnostics diags, IUniqueConstraint <T> constraint) where TProperty : class { diags.ReportError(value.Location, constraint.FormatMessage(entity)); }
public static void ReportError <T, TProperty>( T entity, TProperty value, IDiagnostics diags, IUniqueConstraint <T> constraint) { diags.ReportError( entity is ISourceItem sourceItem ? sourceItem.Location : new SourceLocation(), constraint.FormatMessage(entity)); }
public override IEnumerable <IAnnotation> For(IUniqueConstraint constraint) { // Model validation ensures that these facets are the same on all mapped keys var key = constraint.MappedKeys.First(); var table = constraint.Table; if (key.IsClustered(StoreObjectIdentifier.Table(table.Name, table.Schema)) is bool isClustered) { yield return(new Annotation(SqlServerAnnotationNames.Clustered, isClustered)); } }
/// <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 override IEnumerable <IAnnotation> For(IUniqueConstraint constraint) { // Model validation ensures that these facets are the same on all mapped keys var key = constraint.MappedKeys.First(); var isClustered = key.IsClustered(); if (isClustered.HasValue) { yield return(new Annotation( SqlServerAnnotationNames.Clustered, isClustered.Value)); } }
public override IEnumerable <IAnnotation> For(IUniqueConstraint constraint) { // Model validation ensures that these facets are the same on all mapped indexes var key = constraint.MappedKeys.First(); var prefixLength = key.PrefixLength(); if (prefixLength != null && prefixLength.Length > 0) { yield return(new Annotation( MySqlAnnotationNames.IndexPrefixLength, prefixLength)); } }
public void AddConstraint(IUniqueConstraint <T> constraint, IDiagnostics diags = null) { if (constraint == null) { throw new ArgumentNullException(nameof(constraint)); } if (Count != 0 && !Items.All(x => constraint.IsSatisfiedBy(this, x, diags))) { throw new InvalidOperationException( "Cannot add new constraint because it is violated by existing items."); } uniqueConstraints.Add(constraint); }
/// <summary> /// Creates a new <see cref="AddUniqueConstraintOperation" /> from the specified unique constraint. /// </summary> /// <param name="uniqueConstraint"> The unique constraint. </param> /// <returns> The operation. </returns> public static AddUniqueConstraintOperation CreateFrom([NotNull] IUniqueConstraint uniqueConstraint) { Check.NotNull(uniqueConstraint, nameof(uniqueConstraint)); var operation = new AddUniqueConstraintOperation { Schema = uniqueConstraint.Table.Schema, Table = uniqueConstraint.Table.Name, Name = uniqueConstraint.Name, Columns = uniqueConstraint.Columns.Select(c => c.Name).ToArray() }; operation.AddAnnotations(uniqueConstraint.GetAnnotations()); return(operation); }
/// <inheritdoc /> public override IEnumerable <IAnnotation> ForRemove(IUniqueConstraint constraint) { if (constraint.Table[SqlServerAnnotationNames.IsTemporal] as bool? == true) { yield return(new Annotation(SqlServerAnnotationNames.IsTemporal, true)); yield return(new Annotation( SqlServerAnnotationNames.TemporalPeriodStartColumnName, constraint.Table[SqlServerAnnotationNames.TemporalPeriodStartColumnName])); yield return(new Annotation( SqlServerAnnotationNames.TemporalPeriodEndColumnName, constraint.Table[SqlServerAnnotationNames.TemporalPeriodEndColumnName])); yield return(new Annotation( SqlServerAnnotationNames.TemporalHistoryTableName, constraint.Table[SqlServerAnnotationNames.TemporalHistoryTableName])); yield return(new Annotation( SqlServerAnnotationNames.TemporalHistoryTableSchema, constraint.Table[SqlServerAnnotationNames.TemporalHistoryTableSchema])); } }
/// <inheritdoc /> public virtual IEnumerable <IAnnotation> ForRemove(IUniqueConstraint constraint) => Enumerable.Empty <IAnnotation>();
/// <inheritdoc /> public virtual IEnumerable <IAnnotation> For(IUniqueConstraint constraint, bool designTime) => Enumerable.Empty <IAnnotation>();
public static bool GetIsPrimaryKey([NotNull] this IUniqueConstraint uniqueConstraint) => uniqueConstraint.Table.PrimaryKey == uniqueConstraint;
public IEnumerable <IAnnotation> ForRemove(IUniqueConstraint constraint) => _providers.SelectMany(p => p.ForRemove(constraint));
private static void DefaultReportDiagnostic( T entity, TProperty value, IDiagnostics diags, IUniqueConstraint <T> constraint) { diags.ReportError(new SourceLocation(), constraint.FormatMessage(entity)); }