I have below tables with the values.
Account:
| Id | Name | |
|---|---|---|
| 101 | Nasir Uddin | nasir@email.com |
Role:
| Id | Title |
|---|---|
| 101 | Admin |
| 102 | Operator |
AccountRole:
| AccountId | RoleId |
|---|---|
| 101 | 101 |
| 101 | 102 |
Now I want to write a linq to have the result like below:
UserAccount
| AccountId | Name | Roles | |
|---|---|---|---|
| 101 | Nasir Uddin | nasir@email.com | Admin, Operator |
To get the above result I have written the below query in LINQ. But it does not get the expected result.
var userAccount1 = (from account in _db.Accounts
join accountRole in _db.AccountRoles on account.Id equals accountRole.AccountId
join role in _db.Roles on accountRole.RoleId equals role.Id
select new UserAccountInfo
{
AccountId = account.Id,
Name = account.UserFullName,
Email = account.Email,
Roles = string.Join(",", role.Title)
});
