简体   繁体   English

Entity Framework Core 迁移是否会影响 SQL 服务器索引?

[英]Is Entity Framework Core migration can affect SQL Server indexes?

I want to create indexes in my DB SQL Server directly via SSMS for optimization purpose.我想直接通过 SSMS 在我的 DB SQL 服务器中创建索引以进行优化。 I'm using Entity Framework core in my .NET Core web API and using EF Core DB migration.我在我的 .NET Core web API 中使用实体框架核心并使用 EF Core DB 迁移。 Will EF Core migration will affect or delete the existing indexes? EF Core 迁移会影响或删除现有索引吗?

That depends on how you run your migration.这取决于您如何运行迁移。 You have to add another migration which creates indexes and apply only that migration.您必须添加另一个创建索引并仅应用该迁移的迁移。 Refer link here .请参阅此处的链接。

This is something relatively easy to do,这是比较容易做到的,

Running a simple Add-Migration MigrationNameHere from the NPM command line should create you a new migration.从 NPM 命令行运行一个简单的Add-Migration MigrationNameHere应该会为您创建一个新的迁移。

From there its simply a case of population the Up() and Down() with the index creation and dropping via the migrationBuilder.CreateIndex() or the migrationBuilder.DropIndex() methods.从那里它只是通过migrationBuilder.CreateIndex()migrationBuilder.DropIndex()方法使用索引创建和删除填充Up()Down()的情况。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM