I think you have two problems:
One of what you need to know is whether one instance of MyValueObject is equal to another instance.
And secondly, how this should translate into perseverance.
I think you need to look at them separately, because it seems that your angle connects them too close to each other, which seems to me a violation of some DDD principles. The domain does not need to know / care about conservation.
If you are not sure about the effect of the null value of MyField , or (a), it returns a different type than string ; (b) return to it the derived string as EmptyString (or a similar special case ); (c) either override the Equals method and specify exactly what these instances are equal to.
If your ORM cannot translate a specific expression (which includes MyValueObject ) into SQL, then it may normally perform more difficult work at the persistence level (if the comparison comes from an SQL translation - yes, I'm a performance problem, but I'm not sure it is impossible to decide) in favor of maintaining your domain model. It seems that the solution should flow from the βbest for domain modelβ.
@ James Anderson makes a good point. Reserve null for error and failure conditions. I think the Special Case seems more appropriate.
source share