1

Guess, I am missing to notify a navigation property to EF while eager loading nested graph. Please let me know what am I missing ?.

My simplified Object graph

Product (ProductId, IEnumerable<Task>, ProductStatusId, ProductStatus)

ProductStatus (ProductStatusId, Description)

Task (TaskId, ProductId, TaskStatusId, TaskStatus)

TaskStatus (TaskStatusId, Description)

Trying to load Product => with its Tasks => with their TaskStatus

.Include(p => p.ProductStatus)
.Include(p => p.Tasks)
.Include(p => p.Tasks.Select(t => t.TaskStatus))

Getting the following error :

{"Invalid column name 'TaskStatus_ProductStatusId'.\r\nInvalid column name 'ProductStatusId'}

Sampath
  • 63,341
  • 64
  • 307
  • 441
  • Sounds like relationship setup issue. Please post your simplified classes with navigation properties/keys properties and data annotations/fluent setup included. – Ivan Stoev Sep 16 '16 at 12:10
  • 1
    You are right Ivan Stoev, the fluent configuration was having wrong name. (We were writing hundreds of configurations, and this column name mapping is messed up). – Vijay Anand Sep 16 '16 at 13:55
  • Are you sure that your database is up to date and aligned with your object model? – bubi Sep 16 '16 at 13:57
  • Yes Bubi, they are fine. Your analysis is correct. In our project, it's neither code-first or DB first, we do models and DB separately and map them through fluent. That's where the issue got introduced, as we hard code column names there. – Vijay Anand Sep 16 '16 at 15:29

1 Answers1

0

This should Work

  _yourContext.Product   
  .Include(p => p.ProductStatus)
  .Include(p => p.Tasks.Select(t => t.TaskStatus))

You will not need

  .Include(p => p.Tasks)

Because ".Include(p => p.Tasks.Select(t => t.TaskStatus))" will get the Tasks and the TaskStatus from the Task Collection.

srini
  • 170
  • 4