【发布时间】:2019-05-06 21:21:54
【问题描述】:
我在 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 中似乎不受支持。我也没有找到任何与网络相关的东西。
【问题讨论】:
-
HasIndex描述的 here 方法是否解决了问题?它还支持唯一和多列索引。 -
这个我找到了,没有说HasColumnAnnotation函数怎么处理。
-
如何处理?只需将其替换为
HasIndex,这些列注释是 EF6 特定的解决方法,它缺乏用于定义索引的流畅 API。
标签: entity-framework .net-core ef-code-first entity-framework-core ef-core-2.1