开发者

How to implement multi layered "Include" in Entity framework 3.5 (VS 2008)

开发者 https://www.devze.com 2023-03-13 03:29 出处:网络
My DB have two tables - Question and Topic. To implement many-to-many relation, there is a mapping table which has following structure:

My DB have two tables - Question and Topic. To implement many-to-many relation, there is a mapping table which has following structure:

Table TopicQuestionMapping

  • int ID (Primary Key)
  • int QuestionID (Foreign key to Question table)
  • int TopicID (Foreign key to Topic table)

Now, in my EF I got something like

ViewData.Model = DB.QuestionMaster.Include("TopicQuestionMapping").First(x => x.ID == id);

and then I try to fetch topic like

Model.TopicQuesti开发者_开发技巧onMapping.First().TopicMaster.Name

(for simplification, I am just considering the first record)

The query populates the TopicQuestionMapping (I am getting count = 1). But the TopicMaster is null. Howe can I get it work?

It is something like Table A refer to Table B. Table B refer to Table C. I need to get data from Table C.


Include uses .'s to navigate the object graph.

So like .Include("TableA.TableB.TableC")

http://msdn.microsoft.com/en-us/library/bb896272.aspx

0

精彩评论

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