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.
|