如何使用linq查询和返回documentdb中的所有文档

如何使用linq查询和返回documentdb中的所有文档,linq,azure-cosmosdb,Linq,Azure Cosmosdb,似乎不起作用 let problemDocument = documentClient.CreateDocumentQuery<ProblemDatabaseModel>("") problemDocument (problemDocument.Select(fun problem -> problem)) 似乎也不管用。有什么想法吗?如果您想查询文档数据库中的所有文档,请尝试以下代码: documentClient.CreateDocumentQuery(“”.ToLi

似乎不起作用

let problemDocument = documentClient.CreateDocumentQuery<ProblemDatabaseModel>("")

problemDocument
(problemDocument.Select(fun problem -> problem))

似乎也不管用。有什么想法吗?

如果您想查询文档数据库中的所有文档,请尝试以下代码:

documentClient.CreateDocumentQuery(“”.ToList()

请注意,我们可以在documentDB中存储不同的json实体,如果document属性不在您的数据模型中,它将给出一个默认值。我有一个简单的测试:

数据模型:

(problemDocument.Where(fun problem -> problem.id = problem.id))
如果documentDB中的json数据为:

public class Cred
{
    [JsonProperty(PropertyName = "id")]
    public string ID { get; set; }
    [JsonProperty(PropertyName = "title")]
    public string Title { get; set; }
    [JsonProperty(PropertyName = "credits")]
    public int Credits { get; set; }
    [JsonProperty(PropertyName = "authordetails")]
    public AuthDetail AuthInfo { get; set; }
}
client.CreateDocumentQuery(UriFactory.CreateDocumentCollectionUri(“jambordb”、“jamborcols”)).ToList()

结果如下:


从屏幕截图中我们知道,属性“custom”不会包含在我们的数据模型中。积分将给出默认值0。

感谢您的回复。你的答案正是我想要的,但现在我意识到,我其实并不想要我所有的文件。我真正想要的是ProblemDatabaseModel类型的所有文档。有没有一种聪明的方法可以在不使用字符串查询的情况下使用linq实现这一点?linq是否可以支持类型检查功能,如IS_定义的功能?我为不同的文档类型实现了类似的功能,但它需要我添加一个属性“nodeType”:“tag”。然后我使用Where子句筛选出具有该属性的文档。谢谢据我所知,目前还不支持。添加属性是此方案的一种变通方法。
{
  "id": "CDC103",
  "title": "Fundamentals of database design",

  "authordetails": {
    "Name": "dave",
    "Age": 33
  },
  "custom":"test"
}