troubleshooting Question

LINQ - query for pair values

Avatar of allanau20
allanau20 asked on
.NET ProgrammingC#ASP.NET
16 Comments2 Solutions294 ViewsLast Modified:
Hi Experts!

Thanks for reading this.

Say there are three tables:
PostTags:
   PostTagID (PK)
   TagName

PostTagPairs
   PostTagPairID (PK)
   PostID (FK)
   PostTagID (FK)

Posts
   PostID (PK)
   PostTitle
The following query will return TagName associated with Posts:
var myPost = (from bp in db.Posts
              where bp.PostID == postId
              select new
              {
                  bp.PostTitle,
                  tags = from p in bp.PostTagPairs select p.PostTag.TagName
              }).SingleOrDefault();
Question is how do you get the query above to return PostTagID along with TagName and iterate it in a for loop?
foreach(?? in myPost.tags)
       {
         ??
       } 
TIA!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros