所以从前端我得到一个字符串
"test1,test2,test3"
或"test1,test2"
等(我可以在数字上更改它,这不是问题);
在后端我有这个:
class Car
{
public int Id { get; set; }
public string Name { get; set; }
public Color Color { get; set; }
}
public enum Color
{
Red = 1,
Blue = 2,
Pink = 3,
Orange = 4,
}
public async Task<Car> GetAllCars(string searchString)
{
switch (searchString)
{
case "How create here query guestion whcih inlude ENUMS":
query = query.Where( inlude x=> a.Color == x.Contains(x.Color))
break;
default:
query = query.Where(at =>
at.Id.ToString().Contains(searchString)
||
at.Name.Contains(searchString));
break;
}
}
我想返回所有具有相同枚举的查询
如果您想退回所有汽车,那么您需要将返回类型更改为
List
,然后假设您有一些汽车列表(List<Car>
),我们应该按名称和颜色从中选择汽车:
public async Task<List<Car>> GetAllCars(string searchString)
{
return cars.Where(x=>x.Name.Contains(searchString) || x.Color.ToString().Contains(searchString).ToList();
}