Summary
When trying to union two different collections the driver gives "Expression not supported" error.
MongoDB Version: 5.0.3
.NET Driver Version: 2.18.0
Linq Provider: V3
How to Reproduce
1) Create two IQueryable variables for two different collections selecting some fields
2) Combine both of variables created above with Union operation and assign it to new/third variable
3) Try to get total count of records from union.
var fpQuery = (from fanPass in _AGLMongoDBContext.FanPasses.AsQueryable()
|
select new
|
{
|
FanPassId = fanPass.FanPassId,
|
CreatedDate = fanPass.CreatedDate
|
}).AsQueryable();
|
|
var fpHistoryQuery = (from fanPassHistory in _AGLMongoDBContext.FanPassesSubscriptionHistory.AsQueryable()
|
select new
|
{
|
FanPassId = fanPassHistory.FanPassId,
|
CreatedDate = fanPassHistory.CreatedDate
|
}).AsQueryable();
|
|
var fpUnion = fpQuery.Union(fpHistoryQuery).AsQueryable();
|
|
var fpCount = fpUnion.Count();
|
-
-
- Expression of fpQuery variable ***
agl.FanPasses.Aggregate([{ "$project" : { "FanPassId" : "$FanPassId", "CreatedDate" : "$CreatedDate", "_id" : 0 } }])
|
-
-
- Expression of fpHistoryQuery variable ***
agl.FanPassesSubscriptionHistory.Aggregate([{ "$project" : { "FanPassId" : "$FanPassId", "CreatedDate" : "$CreatedDate", "_id" : 0 } }])
|
-
-
- Expression of fpUnion variable ***
agl.FanPasses.Aggregate([]).Select(fanPass => new <>f__AnonymousType1035`2(FanPassId = fanPass.FanPassId, CreatedDate = fanPass.CreatedDate)).Union(agl.FanPassesSubscriptionHistory.Aggregate([]).Select(fanPassHistory => new <>f__AnonymousType1035`2(FanPassId = fanPassHistory.FanPassId, CreatedDate = fanPassHistory.CreatedDate)))
|
Expression not supported: agl.FanPasses.Aggregate([]).Select(fanPass => new <>f__AnonymousType1035`2(FanPassId = fanPass.FanPassId, CreatedDate = fanPass.CreatedDate)).Union(agl.FanPassesSubscriptionHistory.Aggregate([]).Select(fanPassHistory => new <>f__AnonymousType1035`2(FanPassId = fanPassHistory.FanPassId, CreatedDate = fanPassHistory.CreatedDate))).
|
-
-
- Field Data Type ***
FanPassId -> long / Int64
|
CreatedDate -> DateTime
|
|