gpt4 book ai didi

asp.net-core - EF核心缺失方法HasIndex

转载 作者:行者123 更新时间:2023-12-03 16:23:02 25 4
gpt4 key购买 nike

我刚刚开始迁移到SQL数据库,并遇到抛出MissingMethodException的问题。这是引发错误的配置类:

using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Project.Core.Entities.Users;

namespace Project.Persistance.Configuration.Users
{
public class UserClaimTypeConfiguration : IEntityTypeConfiguration<UserClaimType>
{
public void Configure(EntityTypeBuilder<UserClaimType> builder)
{
builder.HasKey(entity => entity.Id);

builder.Property(entity => entity.Name)
.IsRequired()
.HasMaxLength(30);

builder.HasIndex(entity => entity.Name);

builder.Property(entity => entity.Description)
.IsRequired(false)
.HasMaxLength(100);

builder.Ignore(entity => entity.ValueType);
}
}
}

这是我在控制台中遇到的错误:
PM> add-migration user
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MissingMethodException: Method not found: 'Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder`1.HasIndex(System.Linq.Expressions.Expression`1<System.Func`2<!0,System.Object>>)'.
at Project.Persistance.Configuration.Users.UserClaimTypeConfiguration.Configure(EntityTypeBuilder`1 builder)
at Microsoft.EntityFrameworkCore.ModelBuilder.ApplyConfiguration[TEntity](IEntityTypeConfiguration`1 configuration)

我已经尝试过“Goggle”和Microsoft文档,但似乎找不到与此问题有关的任何引用-因此它必须是我的设置。只是不知道是什么原因造成的!

最佳答案

.NET Core 3.0预览版中的重大更改。在预览版4中修复的问题:
ASP.NET Core Issue 8467 (RESOLVED)

关于asp.net-core - EF核心缺失方法HasIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56858582/

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