Is MongoDB C# Driver LINQ Query Syntax missing Async method?

Viewed 1726

LINQ method syntax do have Async method like this:

var peter = await peopleCollection.Find(x => x.Name == "Peter").FirstOrDefaultAsync();

But it doesn't exist in the query syntax, like this:

var peter = await (from x in collection.AsQueryable()
                   where x.Name == "Peter"
                   select x).FirstOrDefaultAsync(); //COMPILETIME ERROR

Is that really true?

An important note if you wanna test: If you have referenced the Entity Framework library and have the using System.Data.Entity; statement, then FirstOrDefaultAsync() exist at compile-time, but it will give and error when it runs.

2 Answers

Probably, your returned type is an IQueryable interface. You should use MongoDB.Driver.Linq.IMongoQueryable<T> interface instead of it.

Related