PBMining

Searching...
Wednesday, November 28, 2012

Joining three table entities using Linq

2:02 AM

When i was working on my web project i suffer with some difficulty to join two distinct table Questions and Tags with one Middle table QuestionTags and get the result with questions and its related tags.

The Problem was to join the below table.

join three table Questions -> questionTags -> Tags

for joining the above table i used this query.

Dim questions = From qt In context.QuestionsTags
                            Join q In context.Questions
                            On qt.QuestionID Equals q.QuestionID
                           Join t In context.Tags
                           On qt.TagID Equals t.TagID
                           Group t By q Into qts = Group
                           Select q, qts Where q.IsPublished = True

Above query group related question tag and join it with questions.