[CSHARP-1420] Members that have no setter, but are set via MapCreator, do not get automapped to elements in 2.0+ driver Created: 21/Sep/15  Updated: 05/Apr/19  Resolved: 05/Apr/16

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

Type: Task Priority: Major - P3
Reporter: David Pfeffer Assignee: Unassigned
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Create a class with a get-only property. Initialize the member in the constructor from a constructor argument. Map the property using MapCreator. Automap the class map as well.

When retrieving the class map, you will get an exception that the argument is unmapped. This differs from 1.x driver behavior.



 Comments   
Comment by Craig Wilson [ 27/Jan/16 ]

David,

Could you provide the information that Robert is requesting above. We were unable to reproduce what you are seeing. Perhaps some code snippets illustrating the issue? Otherwise, we'll close this as cannot reproduce.

Craig

Comment by Robert Stam [ 03/Nov/15 ]

This is the code I've used to attempt to reproduce using both 1.10.1 and 2.1.0:

public class C
{
    private readonly int _f;
 
    public C(int f)
    {
        _f = f;
    }
 
    public int F {  get { return _f; } }
}

public static void Main(string[] args)
{
    BsonClassMap.RegisterClassMap<C>(cm =>
    {
        cm.AutoMap();
        cm.MapCreator(x => new C(x.F));
        cm.MapProperty(x => x.F); // required both in 1.10.1 and 2.1.0
    });
 
    var c = new C(1);
    var json = c.ToJson();
    var rehydrated = BsonSerializer.Deserialize<C>(json);
}

This code worked against both 1.10.1 and 2.1.0, so I guess I need some more information from you to understand exactly what you are reporting.

Comment by Robert Stam [ 03/Nov/15 ]

Can you provide some sample code to help us reproduce this more quickly and accurately?

Thanks.

Comment by David Pfeffer [ 03/Nov/15 ]

Any chance this is going to be fixed soon?

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