entity-framework - EF Core 的 IndexAnnotation
问题描述
我在 EF 6.2 中有这个代码
public class ClientNotificationMap : EntityTypeConfiguration<ClientNotification>
{
public ClientNotificationMap()
{
HasKey(x => x.RelationalId);
Property(x => x.SubscriptionId)
.IsRequired()
.HasMaxLength(400)
.HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute()));
}
}
我想迁移到 Core 2.2
public class ClientNotificationMap : IEntityTypeConfiguration<ClientNotification>
{
public ClientNotificationMap()
{
}
public void Configure(EntityTypeBuilder<ClientNotification> builder)
{
builder.HasKey(x => x.RelationalId);
builder.Property(x => x.SubscriptionId)
.IsRequired()
.HasMaxLength(400)
.HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute()));
}
}
有谁知道怎么改
.HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute()));
在 Core 中,它似乎不受支持。我也没有找到任何与网络相关的东西。
解决方案
最后我写了代码
builder.HasIndex(x => x.SubscriptionId)
.IsUnique();
builder.Property(x => x.SubscriptionId)
.IsRequired()
.HasMaxLength(400);
它至少编译
推荐阅读
- angular - 为什么一个 Angular 8 应用程序闲置了很长时间
- ios - 滚动后第一个 tableview headerview 消失,但其他每个都保持可见
- python-3.x - 一系列的Python真值是函数中的模棱两可的错误
- c++ - 手动加载动态库意味着库中定义的类上的虚函数
- excel - 为什么 SpecialCells(xlCellTypeVisible) 的行为会根据使用它的函数而有所不同?
- spring-boot - SpringBoot:使用指定配置文件运行没有效果
- database - 使用 snapshot.getChildrenCount() 的值时出现问题
- python - 如何在python中定义这行代码以通过mypy检查
- python - Ansible Tower - aws_s3 模块 - 设置 python 解释器并安装依赖项
- google-apps-script - 通过 Google App Scripts 创建输入到工作表中的数据的备份