-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlServer FillFactor for PK is missing #32803
Comments
Yeah, this makes sense. For now, you can insert the ALTER TABLE SQL directly in your migrations to work around this. |
Unfortunately this is not the case, if the migration epoch is reset, or just rolled back/deleted and regenerated, these changes are lost, would have to be manually reapplied, and are therefore not sufficiently durable. (This is exactly the use case I am addressing currently) I was able to implement a custom CSharpMigrationOperationGenerator that injects the FillFactor sql script into into the migration Up for each TableCreate and TableAlter Up operations, it is oversimplified, heavy handed, and fragile. Still would prefer a proper fluent implementation from EFCore. |
That's true, but this amounts to saying that SQL can never be used in migrations; we're unfortunately unable to provide built-in migration support for each and every supported feature of all databases out there - there's far too many, and modeling all the possibilities of all DDL variants is simply unfeasible. I do agree we should implement this (after all we do have it for indexes) - I'm just saying that it's unlikely to be prioritized. It's also not an very difficult thing to do, if you're interested in contributing it. |
I would be interested in picking this up as a first issue. It looks like adding the WITH options and including FILLFACTOR for primary keys to the SQL Generators is what is needed so that HasFillFactor can be used with key properties. Looking through the code, this looks relatively straight forward. While there will be a few changes to handle adding the FillFactor constant for primary keys, the main code will be in the SqlServerMigrationsSqlGenerator, SqlServerKeyExtensions, SqlServerKeyBuilderExtensions classes. |
Please note, .HasAlternateKey() should be included with this work to fill the gap to a complete feature. |
@deano-hunter Sounds good; go for it! |
"FillFactor" was added several versions ago but it is incomplete/broken.
.HasFillFactor() is only settable on explicit/defined Indexes.
In SqlServer, FillFactor can be set on the PK without additional complexity to the Schema.
This is not available with the FillFactor implementation of EFC 8.
This is an incomplete implementation of the feature which is why I am filing as a bug and not as a feature request.
To advertise FillFactor is supported in EF, code like this:
Should produce Sql Schema as:
or at a minimum, provide a fluent option that ultimately executes the following sql as it will cover the PK:
EF Core version: 8
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Win10
IDE: Visual Studio 2022 17.4
The text was updated successfully, but these errors were encountered: