In your ProfileVersion
and ServerInfo
entities you have an Environment
navigation property. By default, Entity Framework will try to create a database column called [Property Name]_[Referenced class PK]
. In your scenario, that's Environment_Id
. The problem, right now, is that you have not done a migration to have this database column created.
If I had to imagine what happened here, I'd say you first created the classes with EnvironmentId
properties, migrated, then later decided to add the navigation properties, Environment
to each, expecting EF to associate that with your existing EnvironmentId
properties. That's where you went wrong. As I said above, EF convention is to look for a database column named Environment_Id
, so if you want EF to use EnvironmentId
instead, you just need to tell it so with the ForeignKey
data annotation:
[ForeignKey("Environment")]
public int EnvironmentId { get; set; }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…