By Diu King,Tiong - 10/7/2010
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...
|
By Edhy Rijo - 10/8/2010
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.
|
By Diu King,Tiong - 10/8/2010
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
|
By Edhy Rijo - 10/8/2010
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.
|
By Diu King,Tiong - 10/8/2010
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.
|
By Edhy Rijo - 10/8/2010
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?
|
By Greg McGuffey - 10/8/2010
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.
|
By Diu King,Tiong - 10/10/2010
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
|
By Edhy Rijo - 10/10/2010
Hi dktiong,
Glad you figured out.
|
By Diu King,Tiong - 10/10/2010
Hi Ehdy,
How do i default my value to topmostvalue if i don't choose anything from that combobox.
please advice
|
By Edhy Rijo - 10/11/2010
dktiong (10/11/2010) Hi Ehdy,
How do i default my value to topmostvalue if i don't choose anything from that combobox.
please advice
Based on your initial requirement, the value in the database will stay NULL, if you want to assign a default value, then in the Business Object there is a method SetDefaultValues() which you can use to just that. I personally try to avoid NULL values in the database so in my table scripts I have a default value at the table level to avoid getting any NULLs.
It is very important when learning to use SF to invest some time in looking at the help file which is very well structure to be aware of what is available to you and also look at the sample code in the help and then search the forums using keywords like in this case I would use "default values" or something along those lines. The forum is rich with many sample code from the community and the chances that a question from a starter SF developer has already being answer is very high.
|
By Diu King,Tiong - 10/11/2010
Hi Edhy,
I did it with your solution and get what you mean, I will invest some of the time to read through the help file.
Thanks alot....
|
By Edhy Rijo - 10/11/2010
You are welcome dktiong.
|