我正在尝试使用Entity Framework创建项目,但是遇到了问题。
创建模型时(我先调用Database.EnsureDeleted()),它将引发:
Unhandled Exception: System.InvalidOperationException: The entity type 'CustomAttributeData' requires a primary key to be defined. at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidateNonNullPrimaryKeys(IModel model) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model) at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model) at Microsoft.EntityFrameworkCore.Internal.SqliteModelValidator.Validate(IModel model) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ValidatingConvention.Apply(InternalModelBuilder modelBuilder) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelBuilt(InternalModelBuilder modelBuilder) at Microsoft.EntityFrameworkCore.ModelBuilder.FinalizeModel() at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy`1.CreateValue() at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel() at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies() at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider() at Microsoft.EntityFrameworkCore.Internal.InternalAccessorExtensions.GetService[TService](IInfrastructure`1 accessor) at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.get_DatabaseCreator() at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureDeleted() at DAL.EF.PaperCutDbIntializer.Initialize(PaperCutDbContext ctx, Boolean recreate) in /home/jack/RiderProjects/Periode2/Papercut/DAL/EF/PaperCutDbIntializer.cs:line 13 at DAL.EF.PaperCutDbContext..ctor() in /home/jack/RiderProjects/Periode2/Papercut/DAL/EF/PaperCutDbContext.cs:line 12 at DAL.EF.PaperCutDbContext.Get() in /home/jack/RiderProjects/Periode2/Papercut/DAL/EF/PaperCutDbContext.cs:line 18 at DAL.EF.TrackedItemRepository..ctor() in /home/jack/RiderProjects/Periode2/Papercut/DAL/EF/TrackedItemRepository.cs:line 10 at BL.ItemManager..ctor() in /home/jack/RiderProjects/Periode2/Papercut/BL/ItemManager.cs:line 13 at BL.GlobalManager..ctor() in /home/jack/RiderProjects/Periode2/Papercut/BL/GlobalManager.cs:line 17 at CA.Program.Main(String[] args) in /home/jack/RiderProjects/Periode2/Papercut/CA/Program.cs:line 16
我觉得这很奇怪,因为我与CustomAttribute无关。 我也尝试从类中删除所有CustomAttributes,但这并没有什么不同。 也许是因为我要序列化一个抽象类而不是一个实现?
我希望有人能指出我正确的方向。