Lookups, null values, and IsDirty

13 views
Skip to first unread message

Jamie Ide

unread,
Mar 26, 2009, 4:08:07 PM3/26/09
to wilsonormapper
I ran into an interesting bug in my code today. An entity was loading
with an ObjectState of Updated, so it was being persisted when I saved
its parent's graph. It took me a long time to discover that it was
loading as Updated, but once I did the reason was fairly easy to track
down. The entity used a lookup mapping on a field that was nullable in
the enity's table. The initial value for the lookup was null but the
default value of the bool property was false so WORM considered it
dirty. I only caught this because a new trigger on the table was
preventing the phantom update.

The moral is to always assign a nullVlaue in a lookup if the lookup
might return null.
Reply all
Reply to author
Forward
0 new messages