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:
- add them in actual migrations (after ef 4.2)
- use new
indexattribute
in ef 6.1 - 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?
manually adding code in migrations ok wouldn't recommend it. still need update model anyway migrations properly
what makes think new , undocumented? there's absolutely nothing wrong this.
definitely don't this. temptation manually cludge database shoudl avoided.
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
Post a Comment