/// <summary> /// Specifies whether underlying tables and associated indexes are available for queries and data modification during the index operation. /// The ONLINE option can only be specified in certain situations, please refer to documentation for SQL Server 2005 and newer. /// </summary> /// <param name="expression">The expression to use to set the <c>WITH(ONLINE=)</c> option</param> /// <param name="active"> /// <c>true</c> /// Long-term table locks are not held. This allows queries or updates to the underlying table to continue. /// <c>false</c> /// Table locks are applied and the table is unavailable for the duration of the index operation. /// </param> public static ICreateConstraintOptionsSyntax Online(this ICreateConstraintOptionsSyntax expression, bool active = true) { var additionalFeatures = expression as ISupportAdditionalFeatures ?? throw new InvalidOperationException(UnsupportedMethodMessage(nameof(Online), nameof(ISupportAdditionalFeatures))); additionalFeatures.AdditionalFeatures[OnlineIndex] = active; return(expression); }
private static void SetConstraintType(ICreateConstraintOptionsSyntax expression, SqlServerConstraintType type) { if (!(expression is ISupportAdditionalFeatures additionalFeatures)) { throw new InvalidOperationException(UnsupportedMethodMessage(type, nameof(ISupportAdditionalFeatures))); } additionalFeatures.AdditionalFeatures[ConstraintType] = type; }
private static void SetConstraintType(ICreateConstraintOptionsSyntax expression, SqlServerConstraintType type) { CreateConstraintExpressionBuilder castPrimaryKey = expression as CreateConstraintExpressionBuilder; if (castPrimaryKey == null) { throw new InvalidOperationException(type + " must be called on an object that implements ISupportAdditionalFeatures."); } ISupportAdditionalFeatures castExpression = castPrimaryKey.Expression.Constraint; castExpression.AddAdditionalFeature(ConstraintType, type); }
/// <summary> /// Set the unique/index constraint type to <see cref="SqlAnywhereConstraintType.NonClustered"/> /// </summary> /// <param name="expression">The expression</param> public static void NonClustered(this ICreateConstraintOptionsSyntax expression) { SetConstraintType(expression, SqlAnywhereConstraintType.NonClustered); }
public static void Clustered(this ICreateConstraintOptionsSyntax expression) { SetConstraintType(expression, SqlServerConstraintType.Clustered); }