Entity Framework Core - Data annotation foreign keys are not generated?

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
RobertK
Posts: 111
Joined: Thu 02 Mar 2017 05:44

Entity Framework Core - Data annotation foreign keys are not generated?

Post by RobertK » Wed 12 Apr 2017 04:44

For Foreign keys columns: When you generate a class model with EFCore template, the foreign key property generated looks something like this

Code: Select all

public virtual long CountryId { get; set; }
Is it missing a foreign key data annotation or a databasegenerated data annotation?

Note: this is validation set to "data annotation" foreign keys just don't get generated?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Entity Framework Core - Data annotation foreign keys are not generated?

Post by Shalex » Wed 12 Apr 2017 17:48

The EF Core template generates fluent mapping for all classes and its properties (including foreign keys) in ModelName.cs.

If you want to add custom attributes:
1) double click diagram surface to open Model Settings and navigate to Model > Settings > Attributes > select the assembly (e.g.: System.ComponentModel.DataAnnotations.dll) with the needed attributes and make sure that the needed attributes (e.g.: ForeignKeyAttribute) are checked in the window below, press OK
2) select the needed attribute in the Attributes collection of a particular class property

Post Reply