Invalid Column Name using Entity Framework

Serdar Kilic

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.

DB Schema

Any assistance on how to resolve this would be greatly appreciated.

Serdar Kilic

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Entity framework : Invalid column name

From Dev

Entity Framework 4: Invalid Column Name

From Dev

Entity Framework 7 : Generating Invalid Column Name

From Dev

Entity Framework 4: Invalid Column Name

From Dev

C# Entity Framework - Invalid column name

From Dev

Entity Framework Invalid Column

From Dev

SqlException 'invalid column name' for composite key tables with Entity Framework

From Dev

Entity Framework: "Invalid column name" error with many to many mapping

From Dev

Entity Framework Invalid column name when adding property that is not in db table

From Dev

Entity Framework suggest invalid field name

From Dev

Entity Framework SqlException: Invalid object name

From Dev

Entity Framework throws Invalid object name

From Dev

ASP.NET MVC /Entity Framework Error - Invalid column name 'Environment_Id'

From Dev

entity framework Invalid column name Id (two foreign keys from the same primary table)

From Dev

Entity Framework Code First - Invalid column ID

From Dev

EntityCommandExecutionException: Invalid column name 'Entity_Id'

From Dev

Using Entity Framework with existing database error: "Invalid column" despite data annotation

From Dev

Entity Framework - changed generated field/column name

From Dev

Entity Framework 7 Foreign Key Column Name

From Dev

Entity Framework Invalid Column (Column Does Not Exist in Database or Code)

From Dev

Entity Framework - Invalid Column Error on non-existent column

From Dev

Entity Framework invalid object name "dbo.EA_EmployeePerformance"

From Dev

Entity Framework invalid object name "dbo.EA_EmployeePerformance"

From Dev

Invalid Column Name Entity guessing a foreign key that isn't there

From Dev

Getting invalid column name using a pivot table

From Dev

Invalid Column Name using Dynamic SQL

From Dev

Getting invalid column name using a pivot table

From Dev

Invalid column name error while using group by

From Dev

GroupBy in LINQ return me invalid values using Entity Framework 4.0

Related Related

  1. 1

    Entity framework : Invalid column name

  2. 2

    Entity Framework 4: Invalid Column Name

  3. 3

    Entity Framework 7 : Generating Invalid Column Name

  4. 4

    Entity Framework 4: Invalid Column Name

  5. 5

    C# Entity Framework - Invalid column name

  6. 6

    Entity Framework Invalid Column

  7. 7

    SqlException 'invalid column name' for composite key tables with Entity Framework

  8. 8

    Entity Framework: "Invalid column name" error with many to many mapping

  9. 9

    Entity Framework Invalid column name when adding property that is not in db table

  10. 10

    Entity Framework suggest invalid field name

  11. 11

    Entity Framework SqlException: Invalid object name

  12. 12

    Entity Framework throws Invalid object name

  13. 13

    ASP.NET MVC /Entity Framework Error - Invalid column name 'Environment_Id'

  14. 14

    entity framework Invalid column name Id (two foreign keys from the same primary table)

  15. 15

    Entity Framework Code First - Invalid column ID

  16. 16

    EntityCommandExecutionException: Invalid column name 'Entity_Id'

  17. 17

    Using Entity Framework with existing database error: "Invalid column" despite data annotation

  18. 18

    Entity Framework - changed generated field/column name

  19. 19

    Entity Framework 7 Foreign Key Column Name

  20. 20

    Entity Framework Invalid Column (Column Does Not Exist in Database or Code)

  21. 21

    Entity Framework - Invalid Column Error on non-existent column

  22. 22

    Entity Framework invalid object name "dbo.EA_EmployeePerformance"

  23. 23

    Entity Framework invalid object name "dbo.EA_EmployeePerformance"

  24. 24

    Invalid Column Name Entity guessing a foreign key that isn't there

  25. 25

    Getting invalid column name using a pivot table

  26. 26

    Invalid Column Name using Dynamic SQL

  27. 27

    Getting invalid column name using a pivot table

  28. 28

    Invalid column name error while using group by

  29. 29

    GroupBy in LINQ return me invalid values using Entity Framework 4.0

HotTag

Archive