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

Expression Trees with an upcasted conversion lose original serializer

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.0
    • 2.0
    • None
    • None

    Description

      The below test should pass, but doesn't because it treats the predicate as an IEntity, not as a MyEntity.

      [TestFixture]
      public class InterfaceSample
      {
          [Test]
          public async Task Test()
          {
              var subject = DriverTestConfiguration.Client.GetDatabase("test").GetCollection<MyEntity>("test");
              await subject.DeleteManyAsync("{}");
              await subject.InsertOneAsync(new MyEntity { Id = 3, Type = "awesome" });
       
              var entity = await Find(subject, 3);
          }
       
          private Task<T> Find<T>(IMongoCollection<T> collection, int id) where T : IEntity
          {
              return collection.Find(x => x.Id == id).FirstOrDefaultAsync();
          }
      }
       
      public interface IEntity
      {
          int Id { get; set; }
      }
       
      public class MyEntity : IEntity
      {
          public int Id { get; set; }
       
          public string Type { get; set; }
      }

      Attachments

        Activity

          People

            craig.wilson@mongodb.com Craig Wilson
            craig.wilson@mongodb.com Craig Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: