Hi @Oneil Drummond
List<UserExtensionVw> userExtensionVws1 = _context.UserExtensionVws.ToList();
From your query statement and result data, I assume the userExtensionVws1
might contains the duplicate UserExtensionVw, which has the same Userid with different Number, right? like this:
Then, if we directly use the query statement, it will get your current result.
To get your required result, before joining the table, you can group the userExtensionVws1 and sort each group by the number property, then get the first item of each group. Code like this:
List<UserExtensionVw> newuserExtensionVws = userExtensionVws1.GroupBy(c => c.Userid).Select(g => g.OrderBy(p => p.Number).First()).ToList();
After that use the filter result to join the tables.
List<UserExtensionVw> newuserExtensionVws = userExtensionVws1.GroupBy(c => c.Userid).Select(g => g.OrderBy(p => p.Number).First()).ToList();
var TableJoin = from e in newuserExtensionVws
join d in userExtensionVws2 on e.Userid equals d.Userid into table
from d in table.ToList()
select new MA400_ViewModel
{
GetUserExtensionVw = e,
GetUserVw = d
};
return View(TableJoin.ToList());
The result as below:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion