Entity Framework Core 7 index attribute usage for multiple unique columns

98 views Asked by At

I have an entity which requires both Email and Title to be unique. What's the diff between [Index(nameof(Email), IsUnique = true), Index(nameof(Title), IsUnique = true)] and [Index(nameof(Email), nameof(Title), IsUnique = true)]?

1

There are 1 answers

0
Guru Stron On

The second one (the [Index(nameof(Email), nameof(Title), IsUnique = true)] one) will generate the composite index which will check uniqueness across multiple columns, i.e. Email + Title pair will be checked for uniqueness, not the individual columns while the first one ([Index(nameof(Email), IsUnique = true), Index(nameof(Title), IsUnique = true)]) will create 2 indexes both unique for corresponding single columns.