I have a problem regarding concepts compatibility between business and data layer, with respect to entities / tables relations and foreign keys enforced on the database layer.
I am using CodeFluent MySql Producer, but I believe the behavior is the same on other Db producers as well.
The question involves one to many simple relationships between entities, which are mapped out to the db as INT datatype fields, with proper foreign keys enforced.
The issue I have is: on the business layer in .NET, the "linking" property for an entity is mapped as Integer type, with default value of -1 (minus one).
This means that, when the information for the linking of the two entities is NON-EXISTENT (not required), the business layer takes into account -1 as the content for the linking property, and this content -1 is also persisted to the database field on the correspondent table.
There lies the problem I need to understand. When I have -1 as content in the database, the associated foreign key is irrelevant / not compliant. This should be set to NULL on the database side, instead of -1. There is no -1 content as primary key in any row to the OTHER target table for the relationship.
One practical difficulty I have is: I can't user data synchronization scripts between databases that were populated with codefluent generated applications, because upon dropping the foreign keys at the beginning of a data synch script, I cannot re-create them later because of all the -1s (minus ones) in place of NULL that are present as a rule for non-existing information in fields representing relationship between 2 tables...
Can you help me understand and solve this issue?
Thanks