I have a following tables/classes str开发者_如何学Cucture in Linq to entities.
Books
{
bookId,
Title
}
Tags
{
TagId
Tag
}
BooksTags
{
BookId
TagId
}
Now I need to write a query which gives me result like this
Class Result
{
bookId,
Title,
Tags
}
Tags should be comma separated text from the tags table by joining all three tables. How to get it done.
Thanks
Parminder
(from b in books
select new { BookId = b.BookId,
Title = b.Title,
Tags = bookTag.Where(bt => bt.BookId == b.BookId).Select(bt => tags.Single(t => t.TagId == bt.TagId).TagTitle)
}).ToList().Select( t => new
{ BookId = b.BookId,
Title = b.Title,
Tags = string.Join(", ", t.Tags.ToArray())
}
精彩评论