Difference between revisions of "Entity Framework"
From MgmtWiki
(→Troubleshooting) |
(→Troubleshooting) |
||
Line 11: | Line 11: | ||
* [https://stackoverflow.com/questions/60600835/the-entity-type-access-requires-a-primary-key-to-be-defined-if-you-intended-t The entity type 'Access' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()'] is an error that occurs if a POCO class is used in a Dataset table that does not designed to be a db table in its own right. The answer is to mark the POCO class with an [owned] annotation. | * [https://stackoverflow.com/questions/60600835/the-entity-type-access-requires-a-primary-key-to-be-defined-if-you-intended-t The entity type 'Access' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()'] is an error that occurs if a POCO class is used in a Dataset table that does not designed to be a db table in its own right. The answer is to mark the POCO class with an [owned] annotation. | ||
+ | * Annotation of a foreign key is described in the blog [https://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-first.aspx Data Annotations - ForeignKey Attribute in EF 6 & EF Core.] | ||
==References== | ==References== | ||
[[Category: Best Practice]] | [[Category: Best Practice]] |
Latest revision as of 12:58, 24 June 2021
Full Title
This wiki page is about the Microsoft ORM called Entity Framework including best practices and troubleshooting on ASP.NET.
Context
The context is a ASP.NET Core package version 5 or up that is deployed as a complete package.
Problems
Entity Framework assumes a configuration which makes it easy to get running, but hard to adapt to other environments.
Troubleshooting
- The entity type 'Access' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()' is an error that occurs if a POCO class is used in a Dataset table that does not designed to be a db table in its own right. The answer is to mark the POCO class with an [owned] annotation.
- Annotation of a foreign key is described in the blog Data Annotations - ForeignKey Attribute in EF 6 & EF Core.