Reputation: 71
I'm trying to use Entity Framework with a set of entities defined as a part of net standard2.0 nuget package. The project that uses Entity framework is a net472 project. When I'm building the model in tests, I'm seeing the below error
System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:
CodeFirstNamespace.<TestEntity>: : EntityType 'TestEntity' has no key defined. Define the key for this EntityType.
TestEntities: EntityType: EntitySet 'TestEntity' is based on type 'TestEntity' that has no keys defined.
The above error says that one of the entities does not have keys defined, but it has key attributed defined. Below is the entity definition
[Table("TestEntity")]
[FilterSupported]
internal sealed class TestEntity
{
[Key]
[Column("entity1Id", Order = 1)]
public int TestId{ get; set; }
public RelatedEntity entity1Id{ get; set; }
[Key]
[Column("entity2", Order = 2)]
public int entity2Id { get; set; }
public RelatedEntity2 entity2 { get; set; }
}
Below are the references used in the project
This definition worked fine till "System.ComponentModel.DataAnnotations" was replaced with "System.ComponentModel.Annotations".
Is there any way that I can fix this or should I move to use Entity core as it supports dot net standard ?
Thanks in advance
Upvotes: 2
Views: 1186
Reputation: 10600
In the .NET 4.7.2 project, remove the System.ComponentModel.DataAnnotations reference and instead, reference the same Nuget package (System.ComponentModel.Annotations). You will probably have to add a binding redirect.
Upvotes: 1