dotnet / dotnet/efcore

SQL Server Primary key/Unique contrainst index with options DATA_COMPRESSION

Open
#33,145 4 comments 2 reactions 0 assignees View on GitHub
area-model-building area-sqlserver customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

In #30408 index options "DATA_COMPRESSION" is supported, I think there is another place where the same thing is needed. It's the primary key when creating a table for an entity.

Currently I create a custom class extends SqlServerAnnotationProvider to add annotation for data compression as following:

```
public class ExtendedSqlServerAnnotationProvider : SqlServerAnnotationProvider
{
public ExtendedSqlServerAnnotationProvider(RelationalAnnotationProviderDependencies dependencies) : base(dependencies)
{
}

public override IEnumerable For(IUniqueConstraint constraint, bool designTime)
{
foreach (var annotation in base.For(constraint, designTime))
{
yield return annotation;
}

if (!designTime)
{
yield break;
}

var key = constraint.MappedKeys.First();

var table = constraint.Table;

var dataCompression = key.GetDataCompression(StoreObjectIdentifier.Table(table.Name, table.Schema));
if(dataCompression.HasValue)
{
yield return new Annotation(SqlServerAnnotationNames.DataCompression, dataCompression.Value);
}

}
}
```

And then I extend SqlServerMigrationsSqlGenerator to build SQL for index options according to this annotation in AddPrimaryKeyOperation and AddUniqueConstraintOperation.

Finally I add extension methods xxx.UseDataCompression like the way index does.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.