开发者

Self-Tracking Entity Sets and loading realated entites with include problem

开发者 https://www.devze.com 2023-01-25 05:37 出处:网络
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 rel

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? Than开发者_Go百科ks in advance for any help!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消