There is the following code in ASP .NET

public class Area // Район { [Key] public int AreaId { get; set; } public string Name { get; set; } [ForeignKey("RegionId")] public Region RegionId { get; set; } public byte[] Map { get; set; } } public class Region // Область { [Key] public int RegionId { get; set; } public string Name { get; set; } public byte[] Map { get; set; } } public class EFDbContext : DbContext { public DbSet<Area> Areas { get; set; } public DbSet<Region> Regions { get; set; } } 

I have an error when building

The ForeignKeyAttribute on property 'RegionId' on type 'UkraineColleges.Domain.Entities.Area' is not valid. It was not found on the dependent type 'UkraineColleges.Domain.Entities.Area'. The list of foreign key property names.

There is a ready-made database in the App_Data folder, I try to connect it. I work for the first time with the Entity Framework, ASP .Net used it before, but instead of the database, there was a manually created data store. Before that, there were also errors, but re-reading EF sources replaced some errors with others, and here I cannot find a replacement anymore ... Help someone who knows, and if you can, give a couple of tips with the Code-First model who worked with EF

  • Change the RegionId property RegionId to int , to create a navigation property, add the following property public Region Region {get;set;} and set the annotation for it - Bald

0