I'm using Entity Framework to generate my model and whilst the generation of the model itself is successful I'm getting the following error when querying the database.
Invalid column name 'EmployeeDealer_EmployeeDealerID'
The code that throws the exception is:
var employee = db.Employees.Where(emp => emp.EmployeeID == employeeId).FirstOrDefault();
It all looks fairly straightfoward so I'm assuming EF hasn't been able to generate the proper keys or ORM classes?
Here's the DB Schema for the related tables.
Any assistance on how to resolve this would be greatly appreciated.
I ended up resolving this by changing the modified classes. Within the constructor in the Employee class I removed the following statement:
this.Employees = new List<Employee>();
and also removed the following property
public virtual ICollection<Employee> Employees { get; set; }
Then again in the EmployeeDealer class I removed from the constructor:
this.Employees = new List<Employee>();
and also the property
public virtual ICollection<Employee> Employees { get; set; }
So I guess the issue lies in auto-generating an entity for a many-to-many table you need to ensure that the references (I'm assuming the navigation path) between the two other tables are produced correctly.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments