I have a list of Employee Appraisal table, this table has TotalResult
field, the values in this field are between 1 and 10. Another table Result Segmentation has the following columns:
Id int, Max double, Min double, Desc string
Let's say I have this data for Employee Appraisal:
EmpId EmpName TotalResult
--- ------- -----------
1 Jaims 1.5
2 Johny 8.3
3 Moon 5.6
4 Michle 7
5 Mariam 9
6 Kamel 4
Result Segmentation Values
Id Max Min Desc
--- --- --- -----
1 3 1 ~ 30%
2 4 3 40%
3 5 4 50%
4 6 5 60%
5 7 6 70%
6 10 7 ~ 80%
Now, the user has a multi select list of the Rate Segmentation table
if the user chooses 70% and 40%, the query should show these employee appraisals:
EmpId EmpName TotalResult
----- ------- -----------
3 Moon 5.6
6 Kamel 4
4 Michle 7
i wrote this code
if (rateSegIds != null)
{
var rateSegs = _repositoryRateSeg.Query(x => rateSegId.Contains(x.Id)).ToList();
if (rateSeg.Any())
{
foreach (var segmentation in rateSeg)
{
query = query.Where(x => x.TotalResult > segmentation.Min && x.TotalResult <= segmentation.Max);
}
}
}
rateSegIds
is the a list of integers hold the user selectionrateSegs
contains the records from RateSegmataions table according to the list of Ids- query is a queryable object of
EmployeeAppraisal
table
This code works only if the user choose one value from the list, if he/she choose multiple values, the query will return nothing.
Because it's acting like "And" , it should acting like "OR" but I didn't know how to write.