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

Select with create new object throw exception

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.4
    • Component/s: Linq, LINQ3
    • Environment:
      Windows

      Hello. In c# driver version 2.0.1.-rc this is code was worked.

      public class Person
      {
      public string Id

      { get; set; }
      public string Name { get; set; }

      }

      public class SubObject
      {
      public Person Pers

      { get; set; }
      public string SomeData { get; set; }

      public SubObject(Person pers, string someData)

      { Pers = pers; SomeData = someData; }

      }

      static void Main(string[] args)
      {
      MongoClient client = new MongoClient("mongodb://localhost");
      var database = client.GetDatabase("TestDataBase");
      var objectsCollection = database.GetCollection<Person>("TestCollection");
      objectsCollection.Database.DropCollection(objectsCollection.CollectionNamespace.CollectionName);

      var person = new Person()

      { Id = "12", Name = "Alex" }

      ;
      objectsCollection.InsertOne(person);
      person = new Person()

      { Id = "34", Name = "Timmy" }

      ;
      objectsCollection.InsertOne(person);

      var result1 = objectsCollection.AsQueryable().Where(o => o.Name.Length > 4).ToList(); // return 1 object
      var result2 = objectsCollection.AsQueryable().Where(o => o.Name.Length > 4).Select(o => new SubObject(o, "test text")).ToList();
      } // this code worked in 2.0.1-rc, but don't work in 2.2.4

      This is bug or not?

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            IlyaK Ilya
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: