Deserialize Polymorphic Arrays

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.6
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The below program will reproduce.

      class Program
          {
              static void Main(string[] args)
              {
                  var conn = MongoServer.Create();
                  var db = conn.GetDatabase("test");
                  var coll = db.GetCollection("PersonAddresses");
      
                  //coll.RemoveAll();
      
                  //// #1 Please insert a bit of data first by uncommenting the lines. THEN comment them out again.
                  //GetLastErrorResult err;
                  //using (db.RequestStart())
                  //{
                  //    for (int i = 0; i < 1; i++)
                  //    {
                  //        coll.Insert<Person>(new Person()
                  //        {
                  //            Birthday = DateTime.Now,
                  //            FirstName = "Silke",
                  //            Addresses = new Address[] { 
                  //                        new StreetAddress() { City = "Munich" }, 
                  //                        new PhoneAddress() { Kind = 'M', Phone = "+49 179 6960101" } }
                  //        });
                  //    }
                  //    err = db.GetLastError();
                  //    Console.WriteLine(err);
                  //}
      
                  foreach (var z in coll.AsQueryable<Person>())
                  {
                      Console.WriteLine(z);
                  }
      
                  Console.Read();
              }
          }
      
          public class Person
          {
              public Guid Id { get; set; }
              public DateTime Birthday { get; set; }
              public string FirstName { get; set; }
      
              public IList<Address> Addresses { get; set; }
          }
      
          public abstract class Address
          {
          }
      
          public class PhoneAddress : Address
          {
              public Guid Id { get; set; }
              public string Phone { get; set; }
              public char Kind { get; set; }
          }
      
          public class StreetAddress : Address
          {
              public Guid Id { get; set; }
              public string Street { get; set; }
              public string City { get; set; }
              public string ZIP { get; set; }
              public string Country { get; set; }
          }
      
          public class EMailAddress : Address
          {
              public Guid Id { get; set; }
              public string EMail { get; set; }
          }   
      

            Assignee:
            Robert Stam
            Reporter:
            Craig Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: