I\'m new to ASP.NET MVC and EF hopefully this is not a silly question
When i pass model to view i\'m getting this error - Exception Details: System.Data.SqlC
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; }