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

Expression Trees with an upcasted conversion lose original serializer

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: None
    • Labels:
      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

            Assignee:
            craiggwilson Craig Wilson
            Reporter:
            craiggwilson Craig Wilson
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: