Repro with 2.19.1:
using MongoDB.Bson; using MongoDB.Driver; var client = new MongoClient(); var db = client.GetDatabase("test"); var coll1 = db.GetCollection<BsonDocument>("coll1"); var coll2 = db.GetCollection<BsonDocument>("coll2"); var query = coll1.AsQueryable().Union(coll2.AsQueryable()); var results = query.ToList();
Output:
Unhandled exception. MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: test.coll1.Aggregate([]).Union(test.coll2.Aggregate([])). at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.ExpressionToPipelineTranslator.Translate(TranslationContext context, Expression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.Translate[TDocument,TOutput](MongoQueryProvider`1 provider, Expression expression) at MongoDB.Driver.Linq.Linq3Implementation.MongoQuery`2.Execute() at MongoDB.Driver.Linq.Linq3Implementation.MongoQuery`2.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Program.<Main>$(String[] args) in /Users/james/Dropbox/code/cases/csharp4627/Program.cs:line 11
- is duplicated by
-
CSHARP-4623 Linq Union Not Working
- Closed