简体   繁体   English

如何在 Entity Framework db-first 项目中添加非聚集索引?

[英]How to add nonclustered indexes in Entity Framework db-first project?

I have a table in SQL Server which includes custom nonclustered indexes for some columns.我在 SQL 服务器中有一个表,其中包括某些列的自定义非聚集索引。 And I have also a project with below versions.而且我还有一个低于版本的项目。

  • .Net Framework 4.6.2 .Net 框架 4.6.2
  • Entity Framework 6.4.4实体框架 6.4.4

I added an entity data model to project based on my existing database (using a database-first approach).我添加了一个实体数据 model 到基于我现有数据库的项目中(使用数据库优先方法)。

Although a SELECT query returns quickly in database, the same query gets a timeout error in the project.尽管SELECT查询在数据库中快速返回,但相同的查询在项目中出现超时错误。 And I thought that EF couldn't add column indexes to the project.而且我认为 EF 无法将列索引添加到项目中。 I searched index names in the project, but there isn't any code about indexes in the project.我在项目中搜索了索引名称,但是项目中没有任何关于索引的代码。

So, how can I add indexes to my database-first model?那么,如何将索引添加到我的数据库优先 model?

So, how can I add indexes to my database-first model?那么,如何将索引添加到我的数据库优先 model?

"database-first" means that you apply design changes to the database first , and then apply any changes to the EF model second. “数据库优先”意味着您首先将设计更改应用于数据库,然后再将任何更改应用于 EF model。

So you just create the indexes in SQL Server using Visual Studio or SSMS , and since EF model doesn't need to change when you add an index, you're done.因此,您只需使用Visual StudioSSMS在 SQL 服务器中创建索引,并且由于 EF model 在添加索引时不需要更改,因此您完成了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修改使用DB-first Entity Framework创建的枚举 - How to modify an enumeration created with DB-first Entity Framework 实体框架DB-First,实现继承 - Entity Framework DB-First, implement inheritance 实体框架4 DB-First依赖注入? - Entity Framework 4 DB-First Dependency Injection? 实体框架DB-First - 我可以从基础模型继承以添加我的功能吗? - Entity Framework DB-First - can I inherit from base model in order to add my functionality? 努力单元测试实体框架6.1.3 DB-first - Effort unit testing Entity framework 6.1.3 DB-first ASP.NET Core DB-first Entity Framework Core 不能自动增加主键 - ASP.NET Core DB-first Entity Framework Core can not auto increment primary key 将实体(和相应的表)添加到EF DB优先模型 - Adding an entity (and respective table) to EF DB-first model 首先,实体框架数据库,如何添加实体关联? - Entity Framework DB first, How to add an entity association? 为Entity Framework代码优先应用程序添加索引的正确方法? - The right way to add indexes for Entity Framework code-first applications? DB-First Entity上下文是否必须匹配数据库模式,即使对于未使用的表也是如此? - Does an DB-First Entity context have to match the database schema, even for unused tables?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM