entity framework - Adding index to a table -
i have table person
: id, name
i have queries like:
select * person name "%abc%".
i have 2 questions:
- how implement query using code-first 5 (ctp5)
- how add index on name column make data retrieval faster based on name in query?
like operator can performed contains function:
var query = p in context.persons p.name.contains("abc") select p;
index must added sql - there no special construction in ef create index. can execute sql db initialization.
first must implement custom initializer:
public class myinitializer : createdatabaseifnotexists<mycontext> { protected override void seed(mycontext context) { context.database.sqlcommand("create index ix_person_name on person (name)"); } }
then must register new initializer:
dbdatabase.setinitializer<mycontext>(new myinitializer());
Comments
Post a Comment