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:

  1. how implement query using code-first 5 (ctp5)
  2. 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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -