[CSHARP-94] Structure support Created: 08/Nov/10 Updated: 20/Nov/20 Resolved: 20/Nov/20 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Feature Request |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Valera Kolupaev | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 14 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Win7 x64, latest C# Driver trunk |
||
| Description |
|
I have noticed that latest C# Driver has some failing tests, for structure support.
|
| Comments |
| Comment by Jeffrey Yemin [ 20/Nov/20 ] |
|
For anyone still watching this issue: the driver does now support immutable structures and mutable structures that have a constructor annotated with [BsonConstructor]. As this covers the most common use cases for structures, we're going to close this issue. If anyone needs further support for structures, please open a new Jira issue. |
| Comment by Jay Bennett [ 26/Jun/14 ] |
|
Any updates on this? |
| Comment by Justin Caldicott [ 27/Jan/14 ] |
|
That would be fine for my use-case, we already have constructors like that. I guess as long as the exception message you get when you try to serialize structs mentions the new convention, then it's still discoverable. Thanks for the prompt attention! |
| Comment by Craig Wilson [ 27/Jan/14 ] |
|
Hey Justin, Hope that clears it up... I'll work on a convention to map the properties and constructor for structs automatically. I'm not sure if we'll make it part of the default convention pack or require you to register it yourself. Making it part of the default conventions could break some people relying on the fact that we don't map structs. Thanks, |
| Comment by Justin Caldicott [ 27/Jan/14 ] |
|
Thanks for the quick response Craig. I've managed to work around it by creating a custom serializer for our structs. It's based on something I saw in a Google forum: https://gist.github.com/bluebirdtech/1d94a88680594406909c There are three downsides to this that I see:
Regarding your approach, being able to create a convention would be great. I'm not so keen on forcing immutability. I agree that in most cases it's a best practise, but it's not always possible. For example, with our on device data store we're able to mark changed objects, then either commit or discard the changes. Discarding the changes requires to update the existing object. |
| Comment by Craig Wilson [ 27/Jan/14 ] |
|
I need to confer with my colleague, but a little testing shows that the work done in
Let me know if this sounds satisfactory and I'll begin working on a solution, hopefully in our next release. |
| Comment by Justin Caldicott [ 26/Jan/14 ] |
|
.NET structs aren't supported at all with Mongo? This does seem like core functionality to be missing. Does anyone have a workaround that doesn't involve making the struct a class? |
| Comment by Christina [ 10/Sep/13 ] |
|
I can't believe this is marked as minor priority... There is no easy workaround and this is important functionality that you are missing! |
| Comment by Jason Fry [ 01/Jul/13 ] |
|
I agree with Michael and Gustavo - this is critical functionality that is missing from this driver. I too have classes with nested structs that will all need to be converted to classes. Please prioritize this bug! |
| Comment by Gustavo Gondim [ 28/Jan/13 ] |
|
I was using MongoDB applied to a DDD project, that used the "Value Objects" as structs inside classes. After the exception, it confused me and forced me to believe the problem was with interface deserialization (which is another problem in the driver). After questions in StackOverflow and after implement custom serialziers for the interfaces, I have found this issue. I rolled back the project to inicial state (without custom serializers) and changed the struct types to classes. It worked. But, in some cases I REALLY will need the types be passed as a value, not as a reference. This is issue should be priorized, and considered a major implementation. I am trying to help you with this and another to issues (interfaces deserialization and LinQ projections). Please, someone give some attention to this issue. |
| Comment by Michael Bertelsen [ 11/Jan/13 ] |
|
I do not understand that this is considered as a Minor bug, and is not resolved? |
| Comment by Travis Laborde [ 09/Feb/12 ] |
|
In the meantime, it would perhaps be easy/quick to add something preventing these from even going INTO the database. Since you won't be able to get them back out again without modifying your classes. Sort of going with the "fail fast" mentality. Let the developer know as soon as possible that this isn't going to work out... |
| Comment by Robert Stam [ 08/Nov/10 ] |
|
Thanks for the information. We probably are not going to implement support for structs until after the 1.0 release. |
| Comment by Valera Kolupaev [ 08/Nov/10 ] |
|
Here is a recipe, for ref parameters in LINQ Expressions: |