I've been searching and reading and trying different things but I can accomplish the most basic thing.
I have a custom object that has several nullable properties. The problem is that when this property already has data it won't set to null. The code is simplified for simplicity on this post.
This method takes data passed on to modify a record in a database. So in the line where I create the subscription object I use a paramter to know if it is a new record or I'm modifying an existing. When I want to modify an existing one, it look in the database for the record and the returns the object populated with the data from the database. Then I overwrite the object properties with the new data and save again. What it is happening is that if I want to overwrite an existing record that has data on the property FechaAlta, and set this date to null, the object property FechaData won't set to null. Hope it is clear enough.
public string ProcessSubscription(string cRMID, string suscripID, DateTime? fechaAlta = null)
{
Subscription subscription = null;
....
subscription = new Suscription(modify)
....
subscription.CRMID = cRMID;
subscription.SuscripID = suscripID;
subscription.FechaAlta = fechaAlta;
....
return _update.UpdateEntity(subscription);
}
This is what the debugger is showing after that line. I tried to just set it to null for test purposes . Image from the debugger
Subscription.FechaAlta, what happens in the debugger and what value does the record have in the Db before/after etc.nullvalue in .net is very different to aNULLvalue on a database; the later is usually treated asDbNullin .net. Of course this depends on the DBMS and the type of integration you use.