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

UpdateDefinitionBuilder fails when stated type does not match field type

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.4
    • Affects Version/s: 2.4.2, 2.4.3
    • Component/s: Linq
    • Labels:
      None
    • Environment:
      Windows

      When using UpdateDefinitionBuilder to update a document property of any enumerable parsing in an object, the serializer will change the property from type array to type object adding _t and _v.

      Adding these unit tests to UpdateDefinitionBuilderTests will expose the problem:

      [Fact] // This test succeeds
      public void Set_Untyped_String()
      {
      	var subject = CreateSubject<Person>();
      	var firstName = "Linus";
      
      	Assert(subject.Set(x => x.FirstName, firstName), "{$set: {fn: 'Linus'}}");
      
      	var subject2 = CreateSubject<Person>();
      	object firstName2 = "Julius";
      
      	Assert(subject2.Set(x => x.FirstName, firstName2), "{$set: {fn: 'Julius'}}");
      }
      
      [Fact] // This test fails on the second assert
      public void Set_Untyped_List()
      {
      	var subject = CreateSubject<Person>();
      
      	var pets = new List<Pet> { new Pet { Name = "Tiger" } };
      	Assert(subject.Set(x => x.Pets, pets), "{$set: { 'pets' : [{ 'name' : 'Tiger' }] }}");
      
      	var subject2 = CreateSubject<Person>();
      
      	object pets2 = new List<Pet> {new Pet {Name = "Tiger"}};
      	Assert(subject2.Set(x => x.Pets, pets2), "{$set: { 'pets' : [{ 'name' : 'Tiger' }] }}");
      }
      

      I have also attached a small .net program that simulates what I am doing in order to get this error.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            marloe Martin Lobger
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: