ef-code-first - 如何首先使用代码在 EF Core 中创建列存储索引
问题描述
我们想开始一个新项目,我们决定从一开始就在一些表中使用列存储索引和聚集索引,我们如何使用 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)
{
}
}
}
请注意,您应该将[sch].[TableName]替换为您的表名和架构
推荐阅读
- r - 在对 DT::datatable 中的每一列进行排序后,使行名始终稳定,从 1 开始到 n
- python - Horovod 和 Tensorflow 模糊错误 (train_on_batch)
- python - 使用python创建新变量的问题
- aws-billing - 在 Azure 成本管理中集成 AWS 账单发票
- c# - XMLDocument 加载(XmlReader)与加载(流)
- javascript - 将chrome中的请求发送到python服务器时出现ERR_INVALID_HTTP_RESPONSE
- amazon-web-services - AWS Lambda 中的时间同步
- usrp - 使用 USRP N210 进行 QPSK 解调
- django - Django 网站突然要求用户清除 cookie 以获取 CSRF 令牌
- python-3.x - 无法使用 DearPyGui 函数,例如 set_main_window_size 或 add_drawing