首先用实体框架代码添加索引(CTP5) [英] Add index with entity framework code first (CTP5)

查看:130
本文介绍了首先用实体框架代码添加索引(CTP5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



更新:请参阅此处,EF 6.1如何处理这一点(正如 juFo

解决方案

您可以利用新的CTP5的ExecuteSqlCommand >方法在数据库类,允许对数据库执行原始SQL命令。



为此目的,调用SqlCommand方法的最佳位置是在自定义Initializer类中已被覆盖的Seed方法中。例如:

  protected override void Seed(EntityMappingContext context)
{
context.Database.ExecuteSqlCommand CREATE INDEX IX_NAME ON ...);
}


Is there a way to get EF CTP5 to create an index when it creates a schema?

Update: See here for how EF 6.1 handles this (as pointed out by juFo below).

解决方案

You can take advantage of the new CTP5’s ExecuteSqlCommand method on Database class which allows raw SQL commands to be executed against the database.

The best place to invoke SqlCommand method for this purpose is inside a Seed method that has been overridden in a custom Initializer class. For example:

protected override void Seed(EntityMappingContext context)
{
    context.Database.ExecuteSqlCommand("CREATE INDEX IX_NAME ON ...");
}

这篇关于首先用实体框架代码添加索引(CTP5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆