Entity Framework Core primary key required for CustomAttribute





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm trying to make a project using Entity Framework, but I've run into a problem.



When the model is created (I call Database.EnsureDeleted() first) it throws:




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



Which I find rather odd because I have nothing to do with CustomAttribute.
I've tried removing all CustomAttributes from my classes as well, but that didn't make a difference.
Maybe it's because i'm serializing an abstract class rather than an implementation?



I hope someone can point me in the right direction.










share|improve this question























  • What happens in PaperCutDbContext's constructor?

    – Gert Arnold
    Jan 4 at 15:18











  • Can you simplify your DbContext and entity classes enough to post a repro in your question?

    – David Browne - Microsoft
    Jan 4 at 16:08


















0















I'm trying to make a project using Entity Framework, but I've run into a problem.



When the model is created (I call Database.EnsureDeleted() first) it throws:




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



Which I find rather odd because I have nothing to do with CustomAttribute.
I've tried removing all CustomAttributes from my classes as well, but that didn't make a difference.
Maybe it's because i'm serializing an abstract class rather than an implementation?



I hope someone can point me in the right direction.










share|improve this question























  • What happens in PaperCutDbContext's constructor?

    – Gert Arnold
    Jan 4 at 15:18











  • Can you simplify your DbContext and entity classes enough to post a repro in your question?

    – David Browne - Microsoft
    Jan 4 at 16:08














0












0








0








I'm trying to make a project using Entity Framework, but I've run into a problem.



When the model is created (I call Database.EnsureDeleted() first) it throws:




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



Which I find rather odd because I have nothing to do with CustomAttribute.
I've tried removing all CustomAttributes from my classes as well, but that didn't make a difference.
Maybe it's because i'm serializing an abstract class rather than an implementation?



I hope someone can point me in the right direction.










share|improve this question














I'm trying to make a project using Entity Framework, but I've run into a problem.



When the model is created (I call Database.EnsureDeleted() first) it throws:




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



Which I find rather odd because I have nothing to do with CustomAttribute.
I've tried removing all CustomAttributes from my classes as well, but that didn't make a difference.
Maybe it's because i'm serializing an abstract class rather than an implementation?



I hope someone can point me in the right direction.







c# .net entity-framework






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 4 at 14:35









GoodOldJack12GoodOldJack12

113




113













  • What happens in PaperCutDbContext's constructor?

    – Gert Arnold
    Jan 4 at 15:18











  • Can you simplify your DbContext and entity classes enough to post a repro in your question?

    – David Browne - Microsoft
    Jan 4 at 16:08



















  • What happens in PaperCutDbContext's constructor?

    – Gert Arnold
    Jan 4 at 15:18











  • Can you simplify your DbContext and entity classes enough to post a repro in your question?

    – David Browne - Microsoft
    Jan 4 at 16:08

















What happens in PaperCutDbContext's constructor?

– Gert Arnold
Jan 4 at 15:18





What happens in PaperCutDbContext's constructor?

– Gert Arnold
Jan 4 at 15:18













Can you simplify your DbContext and entity classes enough to post a repro in your question?

– David Browne - Microsoft
Jan 4 at 16:08





Can you simplify your DbContext and entity classes enough to post a repro in your question?

– David Browne - Microsoft
Jan 4 at 16:08












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54040980%2fentity-framework-core-primary-key-required-for-customattribute%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54040980%2fentity-framework-core-primary-key-required-for-customattribute%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Angular Downloading a file using contenturl with Basic Authentication

Olmecas

Can't read property showImagePicker of undefined in react native iOS