DocumentDB request using a property other than Id
I want to query my documents in my DocumentDB. I want to use LINQ to handle DocumentDB request and want to query for facebookUsername field.
If I use the code below to request a standard Id field, it works great, but when I try to do it using the facebookUsername field, I get a compilation error that reads
"'Microsoft.Azure.Documents.Document' does not contain a definition for 'facebookUsername' and no extension method 'facebookUsername' Taking a first argument of type" Microsoft.Azure.Documents.Document "can be found (do you see using directive or assembly reference? ) "
Here's the code I'm currently using to request the Id and it works. I just want to get a request in the facebookUsername field.
dynamic doc = (from f in client.CreateDocumentQuery(collection.DocumentsLink)
where f.Id == myId.ToString()
select f).AsEnumerable().FirstOrDefault();
How can I change the code for requesting on the facebookUsername field?
source to share
var families = from f in client.CreateDocumentQuery<Family>(colSelfLink)
where f.Address.City != "NY"
select f;
will give you a list where Family is: {"Address": {"City": "NY"}}}
If in my case you don't have a Family object, you cannot use Linq to evaluate queries on dynamic objects. Then you need to use SQL Query Grammar.
var families = client.CreateDocumentQuery<Family>(colSelfLink. "SELECT * FROM c WHERE field=value").AsEnumnerable();
must work.
source to share