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

Allow projections after OfType()

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.5
    • Affects Version/s: 1.4.2
    • Component/s: None

      Projections are deliberately not allowed on an expression using OfType().

      The following test illustrates the desired behaviour:

              public abstract class Base
              {
                  public string A { get; set; }
              }
      
              public class T1 : Base
              {
                  public string B { get; set; }
              }
      
      
              [Test]
              public void ProjectAfterOfTypeTest()
              {
                  var server = MongoServer.Create(mongo.WriterConnectionString);
                  var db = server.GetDatabase(mongo.Database);
                  var collection = db.GetCollection<Base>("ProjectTest");
      
                  var t1 = new T1 { A = "T1.A", B = "T1.B" };
              
                  collection.Insert(t1);
              
                  var query = from t in collection.AsQueryable().OfType<T1>() select t.B;
                  var results = query.ToList();
                  Assert.That(results.Count, Is.EqualTo(1));
                  Assert.That(results[0], Is.EqualTo("T1.B"));
              }
      

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

              Created:
              Updated:
              Resolved: