Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4623

Linq Union Not Working

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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.

          • Code ***

       

      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))) 

       

       

          • Error ***

       

      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 

             

            Assignee:
            patrick.gilfether@mongodb.com Patrick Gilfether (Inactive)
            Reporter:
            uday.dangrecha@gmail.com Uday Dangrecha
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: