Skip to content

Code first migrations fail to create multi column indexes#46

Closed
cakkermans wants to merge 1 commit intonpgsql:devfrom
Vereyon:dev
Closed

Code first migrations fail to create multi column indexes#46
cakkermans wants to merge 1 commit intonpgsql:devfrom
Vereyon:dev

Conversation

@cakkermans
Copy link
Copy Markdown

According to MSDN it is possible to specify multi column (unique) indexes using attributes. Hence I would expect them to be created accordingly during a migration. Unfortunately only the first column is added :/

https://msdn.microsoft.com/en-us/data/jj591583.aspx#IndexMulti

I checked the Migration SQL generator and it looks fine. For some reason it seems like the entity framework is not passing on the complete set of columns.

Am I missing something?

This pull request expands on the migration unit tests to demonstrate the problem.

@roji roji changed the title Code frist migrations fail to create multi column indexes Code first migrations fail to create multi column indexes Sep 14, 2016
@Iamcerba
Copy link
Copy Markdown

@cakkermans

`[Index("PostDate_Unique_Idx", 1, IsUnique = true)]

public virtual Post Post { get; set; }`

Is this correct that you are adding indexes to navigation property? As far as I know annotations on navigation properties do not work.
Have you tried to add this index explicitly to the foreign key "PostId"?

@rwasef1830
Copy link
Copy Markdown
Contributor

@cakkermans @Iamcerba I have checked this. This is not a bug of EntityFramework6.Npgsql...
Annotations on navigation properties are not passed to us by Entity Framework 6, if you create a foreign key property (PostId) and add the annotation there, the multicolumn index is created correctly.

This is a limitation/bug of Entity Framework 6.
I am closing this pull request.

@rwasef1830 rwasef1830 closed this Sep 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants