Null value as a default value


Author
Message
Diu King,Tiong
Diu King,Tiong
StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)
Group: Forum Members
Posts: 43, Visits: 264
Hi all,

Initially i set my foreign key's field's column properties's Default value or Binding to 0. After while i want back Null values to be saved and i remove 0 from Default value or Binding. However still default value 0 but not Null values saved.

Please advice...
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi dktiong,

This is handle by the framework via the Custom Field Property of the field in the Business Object.  In this form, look at the "NULL Value Option" and choose the one that fits your needs, in your case I think you may use the option of "Return Alternate on Null / Set Null on Alternate (Value Type)".

With the above option the BO field property will setup the value you defined when a Null is found and if it has not changed, then it will set NULL back.

Edhy Rijo

Diu King,Tiong
Diu King,Tiong
StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)
Group: Forum Members
Posts: 43, Visits: 264
Hi Edhy,

let me give an example:

2 tables there are the purchase order and customer. In the purchase order table, there have customer link into it as a foreign key. I did set referential integrity for this relationship between purchase order and customer.

My problem is when i try to insert new record for purchase order and i didn't choose customer, suppose foreign key customer inside purchase order table is default to NULL. Strataframe framework do prompt me the message like "The insert statement conflicted with the foreign key constraints.........................."



Please advice 
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
dktiong (10/8/2010)
I did set referential integrity for this relationship between purchase order and customer.
My problem is when i try to insert new record for purchase order and i didn't choose customer, suppose foreign key customer inside purchase order table is default to NULL. Strataframe framework do prompt me the message like "The insert statement conflicted with the foreign key constraints.........................."


Where did you set the referential integrity: in MS-SQL or in the StrataFrame (SF) Business Objects?

If you created the RI in MS-SQL, then delete it since using StrataFrame you really don't need it unless you will be adding records outside StrataFrame. SF handles the relationship via the Business Object where you can do as many relations as you want and also via code.

Edhy Rijo

Diu King,Tiong
Diu King,Tiong
StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)
Group: Forum Members
Posts: 43, Visits: 264
yes Edhy, i created the RI in MS-SQL. I need RI when i do the delete record. RI will search if deleted record got reference at others table then delete will not successful on that record.

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Ok, then you must use the BO NULL Value Option as I explained before to force the NULL value back to the field.  Have you try that?

http://forum.strataframe.net/Uploads/Images/aa3f4111-28f4-4a8a-9397-047b.png

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Hi dktiong,

I'll add to what Edhy has already stated, as there still seems to be some confusion.  I'm guessing that you are using key fields that have a data type of int.   If you do customization of this sort of field in the BO Mapper, it will default to a value of zero, because in .NET an int must have a value and it defaults to zero.  In the database, it can be null and in fact needs to be null for RI to work.

The solution is to setup the field to return/set an alternate value for nulls. This means that the when the value in the database is NULL, you can setup the BO to return another value, like zero.  And if the value of a field in the BO is zero when saved, a NULL actually gets saved to the database.  When doing this you also don't need to set any default as essentially NULL is default in database and zero is default for ints in .NET.  Likely you got the message because you were setting the value to zero and there were no customers with a Key of zero.  Using what I'm talking about, the value would set to null if no customer is set and the db can understand that.

If you use a combobox to allow the selection of the FK value, you'd need to use the TopMostValue property, setting the value to whatever you are returning for null (zero in this example) and you can set some text indicating no FK has been selected.

Diu King,Tiong
Diu King,Tiong
StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)
Group: Forum Members
Posts: 43, Visits: 264
Hi Edhy and Greg,

Thanks for ur solution. my question is same as the link http://forum.strataframe.net/Topic20554.aspx and it did help me.


Thanks again
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi dktiong,

Glad you figured out.

Edhy Rijo

Diu King,Tiong
Diu King,Tiong
StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)
Group: Forum Members
Posts: 43, Visits: 264
Hi Ehdy,

How do i default my value to topmostvalue if i don't choose anything from that combobox.


please advice
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search