[CSHARP-1768] Projection of mongodb BsonId using C# .NET driver 2.2.4 Created: 14/Sep/16 Updated: 07/Feb/17 Resolved: 07/Feb/17 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 2.2.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Yaroslav Mota | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I have the following structure: public abstract class DbEntity [BsonDateTimeOptions(Kind = DateTimeKind.Utc)] public DateTime CreatedAt { get; set; } [BsonDateTimeOptions(Kind = DateTimeKind.Utc)] [BsonDefaultValue(EntityState.Active)] public EntityState State { get; set; } [BsonIgnoreIfNull] } public class Post : DbEntity { public ObjectId UserId { get; set; } public string SourceUrl { get; set; }public Guid? PictureId { get; set; } public PostType Type { get; set; }public string Caption { get; set; } public GeoJsonPoint<GeoJson2DGeographicCoordinates> Location { get; set; }public string LocationName { get; set; } public List<ObjectId> TaggedFriends { get; set; }public List<string> Tags { get; set; } public List<string> GearTags { get; set; }public Activity Activity { get; set; } public int LikesAmount { get; set; }public int CommentsAmount { get; set; } public List<SharingTarget> Shared { get; set; }public List<string> SearchTokens { get { var result = new List<string>(); result.AddRange(Caption.GetTokens()); result.AddRange(Tags); result.AddRange(GearTags); result.AddRange(LocationName.GetTokens()); return result; } set { } } } private class AggregatedPost : Followings { public AggregatedPost(ObjectId ownerId) : base(ownerId) { } public List<Post> Posts { get; set; } } private class UnwindPost : Followings public Post Posts { get; set; }} I run the query where as a projection I use an Expression `<Func<UnwindPost,Post>>` var query = await ).ToListAsync(); As a result I have an exception that says ` Id: ObjectId("57d91c5393846c3c14792522") As you may see, there is no field '_id' here, however id is returned as 'Id'. All my records are stored in mongodb with '_id' field. How can I project the record with '_id' field in mongo syntax that will be mapped correctly to my Post class (preferably using projection that has Expression as an argument)? |
| Comments |
| Comment by Craig Wilson [ 28/Sep/16 ] |
|
Hi Yaroslav, This should be fixed in 2.3.0. Could you please test this and let us know the results? Craig |