I have a a controller action called List that take the following parameters
int Filer, int Field, int Operator, string QueryValue
public enum Filter
{
ActiveEmployee,
OnHoldEmployee,
InactiveEmployee
}
public enum Field
{
Name,
ABRAID,
JobTitle,
LocationCode,
Department
}
public enum Operator
{
Contains,
StartWith,
EndWith,
EqualTo
}
Possible cases:
Select employee where Name Equals "Value"
Select employee where Name EndWith with "Value"
Select employee where Name StartWith with "Value"
Select employee where JobTitle Contains "Value"
Select employee where Department Equals "Value"
I’m using LINQ to query the database
Employees = from p in DB.Employees
where p.AWCID.Contains(queryvalue)
select p;
But thats mean I have to wite nested switch case to cover all cases.
It’s over 180 lines of code to cover 3 variables,
I’m not very aware with LINQ syntax to support multiple values.
Any thoughts?
Thanks.
Assuming the query will be only one type of query (contains, startswith, etc.), I would try something like this:
You could also make the query types an enum.