Like operator can be performed with Contains function:
var query = from p in context.Persons
where p.Name.Contains("abc")
select p;
Index must be added by SQL - there is no special construction in EF to create index. You can execute this SQL from DB initialization.
First you 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 you must register new initializer:
DbDatabase.SetInitializer<MyContext>(new MyInitializer());
Seed()
for seeding data and I think the sql command should be performed inDbMigration.Up()
. I try to access dbContext in theUp()
method but no luck, but I found there isDbMigration.Sql()
. Seems like in myUp()
, I can callthis.Sql("CREATE INDEX IX_Person_Name ON Person (Name)")
. am I in a right track? – Eph