Hello experts
I have a query and everything in my query works well without the last condition, I use the last condition to filter the joined tables, but I get this error: Operator == cannot be applied to operands of type IEnumerable<string> and string.
this is my code:
var query = from t in db.User_Tbl
join f in db.Rest_Tbl.Select(x => new { x.UserNO, x.Result, x.TypeofRest }).Distinct() on t.UserNO equals f.UserNO
join s in db.Rest_Tbl.Select(t => new { t.UserNO, t.ID, t.Days, t.Edate, t.Bdate, t.Category, t.Result, t.TypeofRest }).GroupBy(x => x.UserNO)
.Select(g => new { UserNO = g.Key, Days = g.Sum(x => x.Days), ID = g.Key, TypeofRest = g.Select(x => x.TypeofRest), Result = g.Select(x => x.Result) })
on f.UserNO equals s.UserNO
where s.Result == "Accepted" && s.TypeofRest == "Primary"
select new
{
ID = s.ID,
UserNO = t.UserNO,
UserName = t.UserName,
Days = s.Days
};
var result = query.Distinct().ToList();
MyDataGrid.ItemsSource = result;
that's my DB tables:
Rest_TBl:
ID(P.K)
UserNO(F.K)
Days
TypeOfRest
Result
_______
User_Tbl:
UserName
UserNO(P.K)
________
explain:
The two Rest_Tbl and User_Tbl tables are related by the UserNO field, and I want to join the Rest_Tbl table with the User_Tbl table once to access the UserName field and join the User_Tbl table with itself once to calculate the days field, I want to sum(days)field based on distinct UserNo
What I have tried:
When I use the condition in the second join, I get a wrong result, and the condition must be applied in the last join, which unfortunately leads to an error.