我尝试在IQueryable中使用字典,但我收到运行时错误,我知道问题发生,因为实时IQueryable不熟悉该对象,我尝试将IQueryable转换为IEnumerable,但我遇到问题查询的执行。 有人可以给我一个提示如何执行该功能?DocumentDB不支持的查询
我有以下代码:
Dictionary<String, int> coursesType= new Dictionary<string, int>();
var userQuery = _client.CreateDocumentQuery<ObjectModel.Student>(uriStudentCollection, options).
Where(x =>coursesType.ContainsKey(x.MainCourse)
&& !x.Courses.ContainsKey(requestCourse)).OrderBy(x => x.Grade).AsDocumentQuery();
var feedResponse = await userQuery.ExecuteNextAsync<ObjectModel.Student>();
foreach (var ad in feedResponse.AsEnumerable())
{
results.Add(ad);
}
更新状态:我仍未收到回答我的问题
***更新:我加我的文档的例子。
{
"id": "a5d7f123-80d5-5094-84fb-08c3bc4ccp972",
"StudentName": "Philip",
"Courses": {
"Math": {
"id": "Math",
"Grade": "98",
"Place": "NYC"
}
},
"Rank":"AA"
}
更新号3
我写了下面的查询:
SqlQuerySpec q = new SqlQuerySpec()
{
QueryText = "SELECT * FROM c WHERE (CONTAINS(LOWER(c[\"courseName\"]),@text) OR CONTAINS(LOWER(c[\"courseDescription\"]),@text)) AND (udf.CourseContainsKey(c[\"Courses\"],@courseId)=false)",
Parameters = new SqlParameterCollection()
{
new SqlParameter("@text", text),
new SqlParameter("@courseId", courseId)
}
};
当我写这样的查询,查询做工精细,但如果我添加了ORDER BY命令(c [\“courseName \”]),@ text)或CONTAINS(LOWER(c [\“ courseDescription \ “]),@文本))AND(udf.CourseContainsKey(C [\” 课程\ “],@ courseId)= FALSE)ORDER BY C [\” courseName \ “] ASC”
由于
谢谢,
MAK
嗨,感谢您的回答,它解决了问题的一部分,我有两个问题1.当我们使用Keys.Contains时,如果我们将它与ContainsKey进行比较,我们确实伤害了性能,我看到查询等于IN(\“Collection \”,\“mat \”,\“physic \”)。 2.!x.Courses.Keys.Contains(requestCourse)不工作,它返回一个空集(我确定查询不是空的),有什么不同?查询是ARRAY_CONTAINS(root [\“Courses \”] [\“Keys \”],\“philo \”) – MAK
我检查了查询并更新了我的答案以进行修改。 –
嗨,它仍然没有解决问题,它等于(NOT(root [\“Courses \”] [\“phil \”]!= null),它返回空集:-( – MAK