Reputation: 30344
I am querying DocumentDB using LINQ and want to read only one document e.g. FirstOrDefault. What's the right way to do that? Here's the code that may give me multiple documents. How should I modify it so that it reads only the first document?
dynamic doc = from f in client.CreateDocumentQuery(collection.DocumentsLink)
where f.Id == userId.ToString()
select f;
Upvotes: 0
Views: 154
Reputation: 21825
Just apply FirstOrDefault
on your result:-
dynamic doc = (from f in client.CreateDocumentQuery(collection.DocumentsLink)
where f.Id == userId.ToString()
select f).FirstOrDefault();
Upvotes: 1