我刚刚开始迁移到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文档,但似乎找不到对此问题的任何参考-因此它必须是我的设置。只是不知道是什么原因造成的!