[Solved] InvalidOperationException: The entity type 'TableNameOrModelName' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()'.


Question: How do you solve the error: InvalidOperationException: The entity type 'ArticleGroupCount' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()'.


Login to See the Rest of the Answer

Answer:
If you intend to use the Entity for Displaying Data such as Analytics, then go to your Database Context and remove the "set;" setter from the public virtual DbSet section of the code. This tells the Entity Framework to only use the Entity when getting the Data from the Database. 

[NB] Make sure you leave the get; getter on the DbSet for the above to work.

- If the above solution does not help you solve the error, then create modelBuilder.Entity in the Database Context block of code and define your Entity there. Don't forget to include "entity.HasNoKey(); " inside the modelBuilder.Entity block of code.







For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]