Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Not allowed to update columns in existent rows to `null` #202

Closed
pbu88 opened this Issue · 4 comments

4 participants

@pbu88

Is there any specific reason to ignore null values when updating objects? The code lets me insert null columns inside rows but do not allows me to update certain rows that have values into null.

I commented the part of the code when it performs the check to see if the expando have null values and I could update the values I wanted to null. In my case, this was the expected behavior, is there something I missing?

The code (Massive.cs):
Method: public virtual DbCommand CreateUpdateCommand(dynamic expando, object key)
Before (Not allowing null):
Line 456: if (!item.Key.Equals(PrimaryKeyField, StringComparison.OrdinalIgnoreCase) && item.Value != null) {
After (my modification):
if (!item.Key.Equals(PrimaryKeyField, StringComparison.OrdinalIgnoreCase)){

I didn't want to make a pull request because maybe there's something I'm missing.
BTW, nice work with Massive. It's very light and flexible.

@brndmg

Hi pbu88,
I used DBNull.Value when setting items to null and that works for me.

@pbu88

I see, that should be the way to go then. Had to hack a little bit my ternary operator to make it compile but it's better this way:

From:
client = this.Client != null ? this.Client.Code : null;
To:
client = this.Client != null ? this.Client.Code as object : DBNull.Value;

I suppose this is the intended way to do it since the item.Value != null is very specific about excluding null values in the expando.

Thanks for the reply @brndmg

@robconery
Collaborator

Yeah @brndmg hit it - DBNull.Value is the way to go. The reason is that many people send in POCOs and other objects and if they don't set a particular value, we don't know if it was intentional or not. The idea is to use an anonymous object - but sometimes people send in a typed object - if Massive parsed and used all the null settings... well it would be a crazy fest.

@robconery robconery closed this
@jotte

DBNull.Value will not work for Image type, error:
Operand type clash: nvarchar is incompatible with image
that's because you need to explicit specify SqlDbType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.