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

How to query and return all documents in documentdb using linq

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

problemDocument

好像不行

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

好像不行

(problemDocument.Where(fun problem -> problem.id = problem.id))

好像也不行。有什么想法吗?

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

documentClient.CreateDocumentQuery<ProblemDatabaseModel>("").ToList();

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

数据模型:

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; }
}

如果 documentDB 中的 json 数据是:

{
  "id": "CDC103",
  "title": "Fundamentals of database design",

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

client.CreateDocumentQuery<Cred>(UriFactory.CreateDocumentCollectionUri("jambordb", "jamborcols")).ToList();

结果如下:

从截图中我们知道,属性 "custom" 不会包含在我们的数据模型中。学分将给出默认值 0.