I would like to get orders and joining another table and the problem is there's duplicate order returns.
Order table
Id OrderNumber UserId
1 Ord123 U1
2 Ord124 U2
3 Ord125 U3
4 Ord126 U2
Authorize Customer Table
Id UserId CustomerId
1 U1 U2
2 U3 U2
Current Result for User: U1 (Power User) in viewing orders
Orders
Id OrderNumber UserId
1 Ord123 U1
2 Ord124 U2
2 Ord124 U2
4 Ord126 U2
4 Ord126 U2
I want like this result
Id OrderNumber UserId
1 Ord123 U1
2 Ord124 U2
4 Ord126 U2
So orders of User: U2(Customer) can be viewed by User: U1(Power User) and U3 (Support User). Below is my current implementation in querying orders.
orders =
from items in ctx.Orders
join auc in ctx.UserAuthorisedCustomers
on items.UserId equals auc.CustomerId
into jts
from jtResult in jts.DefaultIfEmpty()
where jts.Any(x => x.UserId == cri.UserId && x.CustomerId == items.UserId)
|| items.UserId == cri.UserId
select items;
And cri.UserId
is User: U1
question from:
https://stackoverflow.com/questions/66056770/linq-query-select-distinct-order 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…