我在asp.net核心中有一个操作方法,其中参数类型数组的字符串包含多个类别名称
public IActionResult Index(string[] categories,)
{
context.category.where(s=> s.name == string[] categories)
}
我想在类别上下文中执行以下查询:类别名称必须包含此数组中的所有值。不使用for
或foreach
循环
像这样:context.category.where(s=> s.name == string[] categories)
答案 0 :(得分:1)
类似这样的东西:
context.Category
.Where(contextCategory => categories.All(c => contextCategory.Contains(c))
.ToList()
答案 1 :(得分:0)
使用Any
是按类别名称对其进行过滤的最佳方法:
Context.Category.AsEnumerable().Where(c => categories.Any(s => c.LatinName == s)).ToList();