1

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.TopicQuestionMapping.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.

1 Answer 1

2

Include uses .'s to navigate the object graph.

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

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.