-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support defining the serializer and BSON representation for a property #358
Comments
It sounds like the existing data in the database isn't actually a |
@Turnerj it doesn't work like that either |
Sorry, I mean change |
Turned out! but to deserialize to string no? |
It is a little more complicated than that unfortunately. So when you use MongoFramework (or MongoDB's driver directly), if you use a So what we see happening here is that the DB has a binary This gets more unclear because, as far as I know, the name of the ID format that MongoDB uses is called "ObjectId". It is probably possible to write some sort of converter system to allow |
Or maybe better explained another way, there are 3 types of IDs for the MongoDB Driver:
Both |
With your example now, you're telling the driver to specifically ignore the default representation for the serializer. There isn't an equivalent way to do so with MongoFramework currently. I've had a look into a few ways I could try and support BSON representation conversion but I'm not really a fan of what I've come up with currently. I'd probably recommend using the appropriate C# type that matches the data in the database. |
@Turnerj Do you think that in a future version of MongoFramework it will allow serialization like MongoDB.Driver allows? |
Yes, mostly. Like I think being able to define what a particular property should be represented as is quite useful but I need to look at the bigger picture of how I'd integrate it with MongoFramework. Right now the very high level design I'm thinking is with MongoFramework's internal mapping system, track the serializer used for a particular property - basically allow you to set The big bit with this piece of work is that it makes MongoFramework responsible about what serializer is used for what property. By that I mean, MongoFramework will be determining the default serializer for each type rather than the driver by default. This is probably a good thing to do long term anyway (gives more flexibility in mapping) but given the wide variety of types that people could use, it becomes complicated ensuring backwards compatibility. The end result then for consumers of MongoFramework would be both a similar attribute like the driver has to define the representation and also have first-party support in the fluent builder system. |
@Turnerj Is it possible to also allow the camelcase convention, if the properties are in pascal case in an entity? |
Yep! You can do it via attributes or the mapping builder, have a look at this part of the readme: https://github.com/TurnerSoftware/MongoFramework#entity-mapping-basics |
Yes, but isn't there a way to make it global by default? |
No, there isn't a way to have a global default for this. It is something that could be achieved with changes to the |
It would be nice to support it in a future version or find a way to support it in older versions too. |
Issue converted to Proposal by @Turnerj 2023-06-04
Proposal
Allow finer control of the serialization system for MongoDB through MongoFramework. Currently you can not control the BSON Representation (eg. C#
string
can't be represented as BSONObjectId
) however doing so allows greater compatibility in a number of scenarios.This could be accomplished well with support for defining the serializer per-property in MongoFramework. With the appropriate extension methods during the builder process, you could then control the representation that would be used. This first-party support would then unlock the ability to do the same attribute-level control of serializer (and optionally representation).
Original Issue
It does not allow me to read the entities of a mongo database due to this problem.
The text was updated successfully, but these errors were encountered: