Skip to content
Advertisement

How to combine same result into one row after inner join in LINQ

I’m new in ASP.NET and LINQ. I want to display book name, publisher name, and author name in index page. One book can have more than one author.

my query for display the result is like this

Then i create the viewModel for displaying the result, the viewModel code look like this

using Join() method it works like Inner Join in SQL, the result of query is like this

But I expect the output of query to be like this

How to join the author value to the same row when it have the same value on book id? Is there any LINQ method to combining it?

Advertisement

Answer

You can group your query by book and publisher and use string.Join to concat the authors name

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement