I need to create a string concatenation with an linq statement. I have the following data:
Section
- Id: 1, Title: Test1
- Id: 2, Title: Test2
Section_User
- SectionId: 1, UserId: 1
- SectionId: 1, UserId: 2
Users
- Id: 1, Name: User1
- Id: 2, Name: User2
I need the following result:
SectionId: 1, Users: User1, User2
I create the following Linq statement:
var query2 = from section in this.context.Sections
from users in section.Users
group section by section2.Id into groupedSection
select new {
SectionId = groupedSection.Key,
Users = string.Join(",", users.Select (x => x.Name)) // compile error, but I don't know how I write the statement correctly
};
Could someone tell me, how I can create a string concatenation on database side (not in-memory) with an linq statement.
Thanks!!
string.formatinstead of join.