想要只阅读一份文件

时间:2014-11-18 03:58:52

标签: c# linq azure-cosmosdb

我使用LINQ查询DocumentDB,并且只想读取一个文档,例如FirstOrDefault。这样做的正确方法是什么?这里的代码可能会给我多个文档。我该如何修改它以便它只读取第一个文件?

dynamic doc = from f in client.CreateDocumentQuery(collection.DocumentsLink)
              where f.Id == userId.ToString()
              select f;

1 个答案:

答案 0 :(得分:1)

只需对结果应用FirstOrDefault: -

dynamic doc = (from f in client.CreateDocumentQuery(collection.DocumentsLink)
              where f.Id == userId.ToString()
              select f).FirstOrDefault();
相关问题