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

Expression Trees with an upcasted conversion lose original serializer

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

      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; }
      }
      

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

              Created:
              Updated:
              Resolved: