[CSHARP-475] Allow projections after OfType() Created: 23/May/12  Updated: 02/Apr/15  Resolved: 24/May/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.4.2
Fix Version/s: 1.5

Type: New Feature Priority: Minor - P4
Reporter: Andy Clapham Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: linq, query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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



 Comments   
Comment by Craig Wilson [ 24/May/12 ]

Merged to master.

Comment by Andy Clapham [ 23/May/12 ]

The comments indicate this has not been implemented simply because of priorities.

It should be possible to implement this by binding the projection lambda to the coversion lambda used for the
OfType to create a converted projection.

Generated at Wed Feb 07 21:36:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.