How to prevent scaffolding from creating a specific index
Closed this issue · 9 comments
entity.HasIndex(e => new { e.A, e.B }, "IX_the_name_of_the_index").IsUnique();
// Need to prevent this line from being generated
One of my tables has a computed column which causes sql server to throw an error when it tries to create the index. I cannot modify this table. How can I tell EF to ignore this index when scaffolding the db?
Attempting to drop the index does not work since the error occurs on creation. Putting an Index
attribute on the entity with the same index name but different columns causes EF to try to create the index twice.
Using EF 8.0.11, MS SQL Server 2014
EF Core Power Tools let's you exclude indexes...
Read the docs 😅 - you can list an array of included indexes for each table..
I saw this note here:
You can also exclude indexes (SQL Server only), for example to work around this EF Core bug - add a list of ExcludedIndexes strings to your table object in efpt.config.json. CLI: excludedIndexes
Exactly what this means is anyone's guess. Perplexity suggested this and it does not work.
I tried this also and it does not work:
{
"Name": "[dbo].[my_table]",
"ObjectType": 0,
"excludedIndexes": [
"IX_name_of_the_index"
]
},
Nor does this:
{
"Name": "[dbo].[my_table]",
"ObjectType": 0,
"exclude": {
"indexes": [
"IX_name_of_the_index"
]
}
},
It needs to be ExcludedIndexes as written and you need the latest version of the VS extension
@ErikEJ Thank you!
Property does indeed need to be ExcludedIndexes
vs excludedIndexes
as shown in the docs.
The CLI
property is there for unknown reasons (?).
The property is not used at the root of the config file but is instead a property of a specific table and is implemented as follows:
{
"Name": "[dbo].[my_table]",
"ObjectType": 0,
"ExcludedIndexes": [
"IX_name_of_the_index"
]
},
@sam-wheat Great! The cli property is there to document the syntax for the Command Line Interface edition of the tool.
@ErikEJ I think the documentation will be much more useful with the addition of an example. Even AI could not figure this one out LOL.
Agree: ErikEJ/EFCorePowerTools#2723