I have a query in linq-to-sql
as follows:
var query = (from users in _context.Users
join consumers in _context.Consumers
on users.usersId equals consumers.consumerId
from clients in _context.Clients.Where(x => x.Id == users.Id).DefaultIfEmpty().Take(1)
where consumerId.Contains(consumers.consumerId)
select new UserConsumerDto
{
FirstName = users.FirstName,
LastName = users.LastName,
ClientName = clients.Name
}).ToList()
The above query returns me several rows; meaning that a user can have multiple clients. Therefore, I added Take(1)
to get only one client for the time being.
Now, when I remove the Take(1)
, several records are returned.
I want to avoid this, by adding the client name in a single record for a user by separated comma.
For eg:
User 1 | ClientA, ClientB
Instead of:
User 1 | Client A
User 1 | Client B
Can someone please help me to achieve this?