Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

FK Column error - MVC Core 2 - SqlException: Invalid column name 'DepartmentID1'.

$
0
0

hi guys,
I have two simple classes with a Primary Key and FK relationship.

In the Sub_Department class, I get the error

> SqlException: Invalid column name 'DepartmentID1'.
System.Data.SqlClient.SqlCommand+<>c.<ExecuteDbDataReaderAsync>b__108_0(Task<SqlDataReader> result)


Here is my code

public class Departments_Category_Registration
{
[Key]
public int CategoryID { get; set; } // This is the PK
public Departments DepartmentID { get; set; } // this is a FK


and my Departments class with the PK

public class Departments
{
[Key]
public int DepartmentID { get; set; }
[Display(Name ="Departments")]
[Required]
public string Department_Name { get; set; }
[Display(Name ="Departments")]
[Required]
public string Description_Long { get; set; }
[Display(Name ="Short Description_Short")]
[Required]
public string Description_Short { get; set; }
public bool IsEnabled { get; set; }
}



however if I update my db to change the FK to department1 it works, funny thing is that I never used 1 in my code, I had changed it from ID to DepartmentID (if that helps)

Secondly, I thought I ask, if its wise to create a separate controller for each model or not ?

Ehi


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>