Reputation: 3250
I tried
CreateDocumentQuery<Document>(this.collection.DocumentsLink)
.Where(doc => doc.GetPropertyValue<string>(CollectionNameProperty) == collectionName)
But it says, that GetPropertyValue is not supported.
I don't have POCO types for documents, as schema is dynamic. Is DocumentDB SQL my only option?
Upvotes: 3
Views: 938
Reputation: 8003
SQL is the best option since LINQ requires type-binding.
You can alternatively query using the type of Dictionary, then convert to Document (either by reading as an ExpandoObject, or by converting using JsonConvert). But SQL is going to be relatively cleaner:
var query = client.CreateDocumentQuery<Dictionary<string, object>>(collectionLink)
.Where(c => (string)c[propertyName] == propertyValue);
Dictionary<string, object> documentAsDictionary = query.AsEnumerable().FirstOrDefault();
Document document = JsonConvert.DeserializeObject<Document>(
JsonConvert.SerializeObject(documentAsDictionary));
Upvotes: 3