[CSHARP-1275] Projection by expression where members are in base class throw exception Created: 12/May/15  Updated: 22/Jun/15  Resolved: 22/Jun/15

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Kieren Johnstone Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-1253 Cannot deserialize inherited members ... Closed

 Description   

The following throws an exception in BsonClassMap, in one of the internal checks:

public class SomeBaseType
{
public int X

{get; set;}
}

public class MyType : SomeBaseType
{
public int Y {get; set;}

}

_collection.AsQueryable().Select(collType => new MyType

{ Y = collType.SomeField; }

);

Basically, if the projection expression attempts to populate a member not directly in the type being constructed.

I will update this issue with more complete code and if possible a PR - just wanted to log it down before I forget.!



 Comments   
Comment by Craig Wilson [ 22/Jun/15 ]

This is a duplicate of CSHARP-1253.

Comment by Craig Wilson [ 12/May/15 ]

It's going to be in here: https://github.com/mongodb/mongo-csharp-driver/blob/master/src%2FMongoDB.Driver%2FLinq%2FProcessors%2FSerializerBuilder.cs#L95. Somehow, we need to build the serializer starting with the base class. The issue we are dealing with here is this: Collection is of type A. User projects into type B. If type B contains mapping information already, it may or may not be accurate based on the source (type A). Hence, we need to build a new serializer for B with the information from A. So, what is happening in this case is that B has a base class and, because of how our class maps are built, we need to map both the base class and the super class.

I think I had seen this with another bug report, but it got lost in the shuffle because it wasn't the main problem. This might or might not be fixable.

Thanks for filing.
Craig

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