c# - The right way to add indexes for Entity Framework code-first applications? -


i've been researching quite while on how add indexes on columns, when work entity framework code-first.

as see it, there 3 methods:

  1. add them in actual migrations (after ef 4.2)
  2. use new indexattribute in ef 6.1
  3. add indexes columns directly

i not fond of either method as:

1: seems quite risky. might want reset migrations , make "initial setup" again. indexes might deleted.

in addition think it's little transparent , hidden quite well.

2: seems quite new , limited documentation. not sure how works?

3: dangerous if re-create database.

so question is: how add indexes in entity framework code-first?

  1. manually adding code in migrations ok wouldn't recommend it. still need update model anyway migrations properly

  2. what makes think new , undocumented? there's absolutely nothing wrong this.

  3. definitely don't this. temptation manually cludge database shoudl avoided.

  4. you didn't mention this, can use fluent syntax, this:

    modelbuilder      .entity<company>()      .property(t => t.name)      .hascolumnannotation(          "index",           new indexannotation(new indexattribute("ix_company_name")         {             isunique = true          })); 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -