0

I'm trying to query a 'course' document in the 'id' database I have, I've got the following:

collUrl = UriFactory.CreateDocumentCollectionUri("id", "course");
            if(client.CreateDocumentQuery(collUrl).Where((x)=>x.Id == "course1").FirstOrDefault() == null){

Yields the error:

[30/01/2018 6:26:19 AM] Exception while executing function: SynchCourse. System.Private.CoreLib: One or more errors occurred. (Query expression is invalid, expression https://mydb-australiaeast.documents.azure.com/dbs/id/colls/course.Where(x => (x.Id == "course1")).FirstOrDefault() is unsupported. Supported expressions are 'Queryable.Where', 'Queryable.Select' & 'Queryable.SelectMany', Windows/10.0.16299 documentdb-netcore-sdk/1.7.1). Microsoft.Azure.DocumentDB.Core: Query expression is invalid, expression https://mydb-australiaeast.documents.azure.com/dbs/id/colls/course.Where(x => (x.Id == "course1")).FirstOrDefault() is unsupported. Supported expressions are 'Queryable.Where', 'Queryable.Select' & 'Queryable.SelectMany', Windows/10.0.16299 documentdb-netcore-sdk/1.7.1. [30/01/2018 6:26:19 AM] Exception while executing function: SynchCourse [30/01/2018 6:26:19 AM] Exception while executing function: SynchCourse. System.Private.CoreLib: One or more errors occurred. (Query expression is invalid, expression https://mydb-australiaeast.documents.azure.com/dbs/id/colls/course.Where(x => (x.Id == "course1")).FirstOrDefault() is unsupported. Supported expressions are 'Queryable.Where', 'Queryable.Select' & 'Queryable.SelectMany', Windows/10.0.16299 documentdb-netcore-sdk/1.7.1). Microsoft.Azure.DocumentDB.Core: Query expression is invalid, expression https://mydb-australiaeast.documents.azure.com/dbs/id/colls/course.Where(x => (x.Id == "course1")).FirstOrDefault() is unsupported. Supported expressions are 'Queryable.Where', 'Queryable.Select' & 'Queryable.SelectMany', Windows/10.0.16299 documentdb-netcore-sdk/1.7.1. [30/01/2018 6:26:19 AM] Function completed (Failure, Id=d2f1ab38-32f2-46a3-9831-94477b113205, Duration=37625ms)

meds
  • 21,699
  • 37
  • 163
  • 314

1 Answers1

1

Please have a try to use the following code.

if(client.CreateDocumentQuery(collUrl).Where((x)=>x.Id == "course1").AsEnumerable().FirstOrDefault() == null)

The reason for AsEnumerable is to

AsEnumerable(TSource)(IEnumerable(TSource)) can be used to choose between query implementations when a sequence implements IEnumerable(T) but also has a different set of public query methods available

For more information, you also could refer to Understanding .AsEnumerable() in LINQ to SQL

Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47
  • 1
    I get the error: (Unable to load DLL 'Microsoft.Azure.Documents.ServiceInterop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)). Microsoft.Azure.DocumentDB.Core: Unable to load DLL 'Microsoft.Azure.Documents.ServiceInterop.dll – meds Jan 30 '18 at 10:42
  • I can't reproduce the issue you mentioned on my side, but I find a smilar [issue](https://github.com/Azure/azure-documentdb-dotnet/issues/202) in the github. If possible please have a try to update the [Microsoft.Azure.DocumentDB](https://www.nuget.org/packages/Microsoft.Azure.DocumentDB/1.19.1) version to 1.19.1. If that is not helpful, there is a reproduce demo project, it will be more helpful. – Tom Sun - MSFT Jan 31 '18 at 01:51