1

In my project, my user class is inheriting from IdentityUser, and because i have alot of users and i'm performing alot of queries against the user email (which is an IdentityUser property) i wish to have it indexed.

How can one index properties of IdentityUser?

I was thinkin about overriding the Email property and put the [Index] annotation, but will this breaks something?

Note that my project is based on ASP.NET MVC 6 template, and i'm using Entity framework code-first approach.

Esko
  • 4,109
  • 2
  • 22
  • 37
bailando bailando
  • 2,121
  • 2
  • 13
  • 17
  • So you are using code-first and entity framework? – Esko Jul 04 '16 at 10:26
  • Yes i do, i have edited my question to include this information, thanks :) – bailando bailando Jul 04 '16 at 10:33
  • Is the email already a primary key for your table in the db? If so, there already is a primary index. Also this might help you http://stackoverflow.com/questions/22618237/how-to-create-index-in-entity-framework-6-2-with-code-first – Esko Jul 04 '16 at 10:37
  • 1
    In IdentityUser, only the Id is a PrimaryKey, but will overriding the Email property and put the [Index] annotation will break anything? i find this to be a better approach than to edit the migration first schema because i might not always use it or i can accidently drop it, where the [Index] annotation will always be there – bailando bailando Jul 04 '16 at 10:45
  • ideally there should be no side affect apart from small performance overhead while adding new user as it will get indexed – Anshul Nigam Jul 04 '16 at 13:27
  • 1
    Ok, will the Original Email Annotation (which are added in the IdentityUser class such as maximumlength) will be applied in my overiding? – bailando bailando Jul 04 '16 at 14:27

0 Answers0