开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜