You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At a high level, SQL Server only supports creating unique constraints with included column lists and filter clause using the CREATE INDEX syntax. The goal is to make it so that Create.UniqueConstraint offers the same expressiveness as Create.Index().OnTable().Column().Unique(): filtered indexes, included column lists.
For SQL Server, the SqlServer2005Generator has an ABI break: public virtual string GetIncludeString(CreateIndexExpression column) has the parameter renamed to public virtual string GetIncludeString(CreateIndexExpression expression). This is considered a minor break, and unexpected that clients would call this method through reflection.
For SQL Server, the extension methods for Create Constraint should no longer return void and return ICreateConstraintOptionsSyntax instead:
Clustered:
was: public static void Clustered(this ICreateConstraintOptionsSyntax expression)
now: public static ICreateConstraintOptionsSyntax Clustered(this ICreateConstraintOptionsSyntax expression)
what this enables: Not much. If you write createConstraintExpression.Clustered().Include("Column1"), it will fail, since it is non-sensical to include a column in a clustered index. If you write createConstraintExpression.Clustered().Filter("Column1 IS NOT NULL"), it will fail, since it is not possible to filter a SQL Server clustered index. The benefit of this API is it makes it easier for the user to refactor their code by simply changing createConstraintExpression.Clustered() to createConstraintExpression.NonClustered().
NonClustered:
was: public static void NonClustered(this ICreateConstraintOptionsSyntax expression)
now: public static ICreateConstraintOptionsSyntax NonClustered(this ICreateConstraintOptionsSyntax expression)
what this enables: Previously, you could only write: Create.UniqueConstraint("UQ_Foo").OnTable("Foo").Column("Bar").Filter("BAR IS NOT NULL").NonClustered();. Now, you can also write: Create.UniqueConstraint("UQ_Foo").OnTable("Foo").Column("Bar").NonClustered().Filter("BAR IS NOT NULL");
Helper extension methods API breaking change:
Rename SqlServerExtensions.Include to SqlServerExtensions.CreateIndexInclude
CreateIndexExpressionNonKeyBuilder should remove public ICreateIndexNonKeyColumnSyntax Include(string columnName) in a future release? It's a question. It's relying on SupportAdditionalFeatures, which is a bit weird given the implementation points to SqlServerExtensions.CreateIndexInclude
The text was updated successfully, but these errors were encountered:
jzabroski
changed the title
Clean up Unique Constraint API
Create.UniqueConstraint API should be as feature complete as Create.Index() for creating unique indexes
Dec 19, 2023
jzabroski
changed the title
Create.UniqueConstraint API should be as feature complete as Create.Index() for creating unique indexes
Create.UniqueConstraint API should be as feature complete as Create.Index for creating unique indexes
Dec 19, 2023
See #1081 (review)
At a high level, SQL Server only supports creating unique constraints with included column lists and filter clause using the
CREATE INDEX
syntax. The goal is to make it so thatCreate.UniqueConstraint
offers the same expressiveness asCreate.Index().OnTable().Column().Unique()
: filtered indexes, included column lists.public virtual string GetIncludeString(CreateIndexExpression column)
has the parameter renamed topublic virtual string GetIncludeString(CreateIndexExpression expression)
. This is considered a minor break, and unexpected that clients would call this method through reflection.void
and returnICreateConstraintOptionsSyntax
instead:public static void Clustered(this ICreateConstraintOptionsSyntax expression)
public static ICreateConstraintOptionsSyntax Clustered(this ICreateConstraintOptionsSyntax expression)
createConstraintExpression.Clustered().Include("Column1")
, it will fail, since it is non-sensical to include a column in a clustered index. If you writecreateConstraintExpression.Clustered().Filter("Column1 IS NOT NULL")
, it will fail, since it is not possible to filter a SQL Server clustered index. The benefit of this API is it makes it easier for the user to refactor their code by simply changingcreateConstraintExpression.Clustered()
tocreateConstraintExpression.NonClustered()
.public static void NonClustered(this ICreateConstraintOptionsSyntax expression)
public static ICreateConstraintOptionsSyntax NonClustered(this ICreateConstraintOptionsSyntax expression)
Create.UniqueConstraint("UQ_Foo").OnTable("Foo").Column("Bar").Filter("BAR IS NOT NULL").NonClustered();
. Now, you can also write:Create.UniqueConstraint("UQ_Foo").OnTable("Foo").Column("Bar").NonClustered().Filter("BAR IS NOT NULL");
SqlServerExtensions.Include
toSqlServerExtensions.CreateIndexInclude
SqlServerExtensions.CreateUniqueConstraintInclude
Additional Considerations
CreateIndexExpressionNonKeyBuilder
should removepublic ICreateIndexNonKeyColumnSyntax Include(string columnName)
in a future release? It's a question. It's relying on SupportAdditionalFeatures, which is a bit weird given the implementation points toSqlServerExtensions.CreateIndexInclude
The text was updated successfully, but these errors were encountered: