gpt4 book ai didi

ef-code-first - 如何使用代码优先在 EF Core 中创建列存储索引

转载 作者:行者123 更新时间:2023-12-05 07:06:32 27 4
gpt4 key购买 nike

我们想开始一个新项目,我们决定从一开始就在一些表中使用 Columnstore 索引和聚簇索引,我们如何使用 Code First EF Core 3.1 做到这一点?

最佳答案

  • 您应该将主键更改为非聚簇索引:

    entity.HasKey(e => e.Id).IsClustered(false);
  • 然后将手动迁移添加到迁移文件夹我添加一个名称为 30000000000001_AddMyColumnStoreIndex.cs 的文件并在文件中添加以下代码

using DDFHandler;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using System.Diagnostics.CodeAnalysis;

namespace MyNameSpace
{
[DbContext(typeof(MyApplicationContext))]
[Migration("30000000000001_AddMyColumnStoreIndex")]
public class V1_AddMyColumnStoreIndex : Migration
{
protected override void Up([NotNullAttribute] MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("CREATE CLUSTERED COLUMNSTORE INDEX [cci] ON [sch].[TableName]");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

be careful that you should replace [sch].[TableName] with your table name and schema

关于ef-code-first - 如何使用代码优先在 EF Core 中创建列存储索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62445923/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com