【发布时间】:2018-03-08 05:23:15
【问题描述】:
我尝试在 IQueryable 中使用字典,但收到运行时错误,我知道问题的发生是因为实时 IQueryable 不熟悉该对象,我尝试将 IQueryable 转换为 IEnumerable,但执行时遇到问题查询。 有人可以给我一个提示如何执行该功能吗?
我有以下代码:
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 命令添加到我收到空集的查询中......
"SELECT * FROM c WHERE (CONTAINS(LOWER(c[\"courseName\"]),@text) OR CONTAINS(LOWER(c[\"courseDescription\"]),@text) ) AND (udf. CourseContainsKey(c[\"Courses\"],@courseId)=false) 按 c[\"courseName\"] ASC" 排序
谢谢
谢谢,
马克
【问题讨论】:
标签: c# linq azure-storage azure-cosmosdb