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

StackOverflow when expression contains IQueryable

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.14.0
    • Affects Version/s: 2.2.3, 2.4.3
    • Component/s: Linq, LINQ3
    • Environment:
      Windows 10, MSSQL 16, .NET 4.6.1, EntityFramework 6.1.3

      1. Create empty console application
      2. Install EntityFramework package (6.1.3)
      3. Install MongoDB.Driver package (2.4.3)

      namespace App
      {
          using System.Collections.Generic;
          using System.Linq;
          using System.Data.Entity;
          using MongoDB.Driver;
      
          class Program
          {
              static void Main(string[] args)
              {
                  var context = new SampleContext();
                  
                  var ids = context.Customers.Select(e => e.CustomerId);
                  var arr = ids.ToArray();
                  
                  var mongoQuery = new MongoClient("mongodb://localhost:27017")
                      .GetDatabase("MyShop")
                      .GetCollection<MongoCustomer>("MongoCustomer")
                      .AsQueryable();
      
                  // OK
                  mongoQuery.Where(e => arr.Contains(e.CustomerId)).ToArray();
      
                  // StackOverflow
                  mongoQuery.Where(e => ids.Contains(e.CustomerId)).ToArray();
              }
          }
      
          public class MongoCustomer
          {
              public int CustomerId { get; set; }
              public string Name { get; set; }
          }
      
          public class Customer
          {
              public int CustomerId { get; set; }
              public string Name { get; set; }
          }
      
          public class SampleContext : DbContext
          {
              public SampleContext() : base("MyShop")
              {
              }
      
              public DbSet<Customer> Customers { get; set; }
          }
      }
      

            Assignee:
            james.kovacs@mongodb.com James Kovacs
            Reporter:
            gushinav Gushchin Anton
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: