Wrong model creation for alternate keys using annotations and removed index #33531
Labels
area-conventions
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
Hello,
Models created for database are wrong if we use alternate keys and have removed
ForeignKeyIndexConvention
. Code snippet:The only difference between
Context0
andContextAnnotated0
is thatContextAnnotated0
has additional attributes on properties, which might and should be redundant in this case.If we run following code:
then we will have two tables with two columns each -
Blog(Id, AlternateId)
andPost(Id, BlogId)
.However, if we run it for annotated context:
Then we will have additional column
BlogAlternateId
inPosts
table.This code is mostly copied from
ModelBuilding101TestBase.OneToManyRequiredWithAlternateKeyTest
. This test passes for SqlServer, because SqlServer by default haveForeignKeyIndexConvention
. I am developing EFCore.Snowflake, where this convention is removed (Snowflake doesn't have indexes) and constructed model is incorrect.Include provider and version information
EF Core version: v8.0.4
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Windows 11 23H2
IDE: Visual Studio 2022 17.9.6
The text was updated successfully, but these errors were encountered: