nhibernate - How to handle null when comparing equality of value objects? -


note: use c# example, problem virtually same in java , many other languages.

assume implement value object (as in value object pattern m. fowler) , has nullable field:

class myvalueobject {        // nullable field (with public access keep example short):     public string myfield; } 

then, when overriding equals(), how treat case when both value objects have myfield set null? equal or not?

in c#, treating them equal seems obvious, because:

  1. this behaviour of equals() when use c# struct instead of class , not override equals().

  2. the following expressions true:

    null == null object.referenceequals(null, null) object.equals(null, null) 

however, in sql (at least in sql server's dialect), null = null false, whereas null null true.

i wondering implementation expected when using o/r mapper (in case, nhibernate). if implement "natural" c# equality semantics, may there ill effects when o/r mapper maps them database?

or maybe allowing nullable fields in value objects wrong anyway?

since orms know relational model, expose way query using sql semantics.

nhibernate, example, provides is [not] null operator in hql, , restrictions.is[not]null in criteria.

of course, there's api these paradigms collide: linq. orms try right thing when comparing null (i.e. replacing is null), although there can issues times, behavior not obvious.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -