EF Core 1.1 generating unique index on FK one-to-one
See original GitHub issueI’m using EF Core 1.1 and created my one-to-one relationships, an example:
EntityTypeBuilder<Account>
.HasOne(a => a.Customer)
.WithOne(a => a.Account)
.HasForeignKey<Account>(a => a.CustomerId)
Now using Add-Migration on my DbContext it generates the following:
migrationBuilder.CreateIndex(
name: "IX_Accounts_CustomerId",
table: "Accounts",
column: "CustomerId",
unique: true);
Is there a way to specify in Fluent to remove the uniqueness from the index? I don’t mind the index being generated, but for my purposes it can not be unique. The reason is that these tables are auditable so there can be duplicate data (outside of the PK). Hence records can contain the same FK id if there were no changes to that FK entity (but maybe changes elsewhere in the record).
TL;DR Any way of making the index non-unique in Fluent for one-to-one FKs?
Issue Analytics
- State:
- Created 7 years ago
- Comments:19 (9 by maintainers)
Top Results From Across the Web
EF Core 1.1 generating unique index on FK one-to-one
Now using Add-Migration on my DbContext it generates the following: migrationBuilder.CreateIndex( name: "IX_Accounts_CustomerId", table: " ...
Read more >Indexes - EF Core
Configuring indexes in an Entity Framework Core model. ... Composite index; Index uniqueness; Index sort order; Index name; Index filter ...
Read more >Generate a composite unique constraint/index, in EF Core ...
[Solved]-Generate a composite unique constraint/index, in EF Core-Entity ... can use (at least in ef core 1.1.0) the string based hasindex method overload...
Read more >EF Core One-to-one Relationships - C# Tutorial
EF Core creates a unique index on the EmployeeId column of the EmployeeProfiles table to ensure that one row in the Employees table...
Read more >dotConnect for SQLite History
The bug with generating fluent mapping for the one-to-one association by the ... GridControl is fixed; The bug with creating indices by EF...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Answered on stackoverflow. http://stackoverflow.com/questions/41170325/ef-core-1-1-generating-unique-index-on-fk-one-to-one/41172323#41172323
thank you