0

I have a problem with .include method of Self-Tracking Entity. My table called documents have relations to tables States, Companies, Workers and Departments. I want to load all documents with this related data. Im tring do this like that:

context.Documents.Include("Workers.Departments.States.Companies").ToList(); 

But this throws me a exception:

A specified Include path is not valid. The EntityType „workflowModel.Department" does not declare a navigation property with the name „States”.

The same error also for Companies. What is strange Workers and Departments works. I does not work also for Company and State (I've used built in pluralization and singularization). I double checked the name on model (Entity Set Name property) and copied the names and still didnt work. Have some one idea what is going on? Or maybe some other method to load all this data? Thanks in advance for any help!

Pax0r
  • 2,324
  • 2
  • 31
  • 49
  • Not exactly sure what is going on without seeing the model, but you should look into patterns with lambdas which make eager loading strongly typed. Saves a lot of headaches like this. I'll try to find you some good links. – Daniel Nov 14 '10 at 19:17
  • 1
    Check out these pages: http://www.codetuning.net/blog/post/Entity-Framework-compile-safe-Includes.aspx http://howdoinetmw.blogspot.com/2009/12/how-do-i-create-type-safe-includes-with.html – Daniel Nov 14 '10 at 19:19
  • Using this include method it's started to working properly, thank you very much! :) – Pax0r Nov 14 '10 at 20:04

1 Answers1

0

The problem is here:

I double checked the name on model (Entity Set Name property) and copied the names and still didnt work

You should look at the Department entity for example and copy the name of the navigation property that represents State. Probably something like this will work (each Department has only one State and NOT many which makes sense):

context.Documents.Include("Workers.Departments.State.Companies").ToList(); 

Also, you should look into State entity and discover the name for Company navigation property and put it in your Include method.

Morteza Manavi
  • 33,026
  • 6
  • 100
  • 83
  • I've tried both plural and singular and it didnt work, but as I said above with this labda version it works ;) – Pax0r Nov 14 '10 at 20:06