using System.Collections;
using System.Collections.Generic;
public static void Main()
List<Post> posts = new List<Post>()
new Post { PostId = 1,Body="hi",PostDate=DateTime.Now,Title="post 1",Draft="" },
new Post { PostId = 2,Body="hiii",PostDate=DateTime.Now,Title="post 2",Draft="" },
new Post { PostId = 3,Body="hiiiii",PostDate=DateTime.Now,Title="post 3",Draft="" },
new Post { PostId = 4,Body="hi hh",PostDate=DateTime.Now,Title="post 4",Draft="" },
List<Category> categories = new List<Category>()
new Category {CategoryId=1,CategoryName="Cat 1" },
new Category {CategoryId=2,CategoryName="Cat 2" },
new Category {CategoryId=3,CategoryName="Cat 3" },
new Category {CategoryId=4,CategoryName="Cat 4" }
List<PostCategory> postcategories = new List<PostCategory>()
new PostCategory { CategoryId = 1, PostId = 4},
new PostCategory { CategoryId = 2, PostId = 3},
new PostCategory { CategoryId = 3, PostId = 1},
new PostCategory { CategoryId = 4, PostId = 2},
List<Author> authors = new List<Author>()
new Author { AuthorId = 1, AuthorName = "Author 1"},
new Author { AuthorId = 2, AuthorName = "Author 2"},
new Author { AuthorId = 3, AuthorName = "Author 3"},
new Author { AuthorId = 4, AuthorName = "Author 4"},
List<PostTag> tagposts = new List<PostTag>()
new PostTag { PostId = 1, TagId = 4},
new PostTag { PostId = 1, TagId = 2},
new PostTag { PostId = 2, TagId = 2},
new PostTag { PostId = 3, TagId = 1},
new PostTag { PostId = 4, TagId = 3}
List<Tag> tags = new List<Tag>()
new Tag { TagId = 1, TagName ="Tag 1"},
new Tag { TagId = 2, TagName ="Tag 2"},
new Tag { TagId = 3, TagName ="Tag 3"},
new Tag { TagId = 4, TagName ="Tag 4"},
var results = from p in posts
join pc in postcategories on p.PostId equals pc.PostId
join c in categories on pc.PostId equals c.CategoryId
join a in authors on pc.PostId equals a.AuthorId
join tp in tagposts on p.PostId equals tp.PostId
join t in tags on tp.TagId equals t.TagId
group new { t, p, c, a } by tp.PostId into g
foreach(var item in results)
Console.WriteLine(string.Join(Environment.NewLine,"Post: "+ item.Post.Title,"Category: "+item.Category.CategoryName,"Author: "+ item.Author.AuthorName,"Tags: "+string.Join(",",tags.Select(x=>x.TagName))));
public int PostId {get;set;}
public string Title {get;set;}
public DateTime PostDate {get;set;}
public string Body {get;set;}
public string Draft {get;set;}
public int CategoryId {get;set;}
public string CategoryName {get;set;}
public class PostCategory
public int PostId {get;set;}
public int CategoryId {get;set;}
public int AuthorId {get;set;}
public string AuthorName {get;set;}
public int AuthorId {get;set;}
public int PostId {get;set;}
public int TagId {get;set;}
public string TagName {get;set;}
public int PostId {get;set;}
public int TagId {get;set;}
public class BlogViewModel
public Post Post { get; set; }
public Category Category { get; set; }
public Author Author { get; set; }
public IEnumerable<Tag> Tags { get; set; }