c# - 如何使用实体框架中的字符串参数类型数组执行 where 查询?
问题描述
我在 asp.net 核心中有一个操作方法,其参数类型为字符串数组,其中包含多个类别名称
public IActionResult Index(string[] categories,)
{
context.category.where(s=> s.name == string[] categories)
}
我想在类别上下文中执行 where 查询,类别名称必须包含此数组中的所有值。不使用for
orforeach
循环
像这样:context.category.where(s=> s.name == string[] categories)
解决方案
可能是这样的:
context.Category
.Where(contextCategory => categories.All(c => contextCategory.Contains(c))
.ToList()
推荐阅读
- python-2.7 - Arduino和Python之间的慢速串行连接
- scala - 如何使用同一流中存在的键对流的元素进行分组?
- html - 需要 Excel VBA 来浏览网站和下载特定文件
- python - 在集群环境中启动和停止 weblogic 服务
- javascript - 在地图中显示 KML 文件
- javascript - 如何为我的 mocha 测试创建自定义挂钩?
- python - 如果我们有多个分类列多类怎么办?
- python - 如何在 Anaconda 中安装 docplex 包?
- sql - 如何通过 Powershell 使用 SQLCMD 添加值逗号分隔的参数调用 SQL 查询
- java - 使用杰克逊没有字符串参数构造函数/工厂方法的 XML 映射来反序列化字符串值(“比利时华夫饼”)