我有一张桌子Person
:id, name
我经常有这样的疑问:
select * from Person where name Like "%abc%".
我有两个问题:
发布于 2011-02-18 04:23:38
Like操作符可以用Contains函数执行:
var query = from p in context.Persons
where p.Name.Contains("abc")
select p;
索引必须由SQL添加- EF中没有创建索引的特殊结构。可以从DB初始化执行此SQL。
首先,必须实现自定义初始化程序:
public class MyInitializer : CreateDatabaseIfNotExists<MyContext>
{
protected override void Seed(MyContext context)
{
context.Database.SqlCommand("CREATE INDEX IX_Person_Name ON Person (Name)");
}
}
然后必须注册新的初始化程序:
DbDatabase.SetInitializer<MyContext>(new MyInitializer());
发布于 2017-07-31 05:32:57
在EF 6中,您可以创建这样的索引
Property(t => t.TotalValue)
.HasColumnAnnotation(
IndexAnnotation.AnnotationName,
new IndexAnnotation(new IndexAttribute("IX_inventory_import_total_value", 1))
);
https://stackoverflow.com/questions/5040795
复制