I'm currently applying the [BsonRepresentation(BsonType.String)]
attribute to all Guid
properties in my domain models to have those properties serialized in string format. Besides being tiresome to do, that doesn't work out sometimes, e.g. with custom Wrapper<T>
classes:
public class Wrapper<T>
{
public T Value { get; set; }
// Further properties / business logic ...
}
When T
is Guid
, the Value
property will be stored as binary data of type UuidLegacy
(as will any property of type Guid
that's not decorated with the above attribute). However, I'd like all Guid
s, including Wrapper<Guid>.Value
, to be represented as a string in the database.
Is there any way to tell the MongoDB C# driver to store all Guid
s in string format?