problems with 1 to 0:1 relations in llblgen designer

Posts   
 
    
Posts: 56
Joined: 08-Jun-2010
# Posted on: 25-Oct-2010 16:54:23   

Hello

I'm Using 8th October Build of llblgen 3.

I have 2 Entities in my system that have a 1 to 0..1 relationship.

I have set this relationship up in the designer and the generated code seems fine. The problem occurs when I try to refresh from the database.

When I refresh llblgen spits out ddl to add a unique constraint on the foreign key. This is incorrect as most of the data will have a null in this column. It also spits out a foreign key constraint with the same problem.

When I skip this setting and refresh the database llblgen removes this relationship because I have RelationshipsFollowDBForeignKeyConstraints set to Default(true). I would like new foreign key constraints to be picked up as relationships by llblgen but replacing this relationship each time I refresh is driving me crazy.

Is there a work around here? - Can I add to the underlaying database so that llblgen recognises a 1 -> 0:1 or can I disable RelationshipsFollowDBForeignKeyConstraints for just this relationship (or entity even?)

Thanks ~Brett

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 25-Oct-2010 17:13:56   

When I refresh llblgen spits out ddl to add a unique constraint on the foreign key..This is incorrect as most of the data will have a null in this column

This statment is not always true. It depends on the database, as some databases alow you to insert more than one NULL in a unique constraint column, as they consider NULL to be of no value, and hence one NULL can't equal another NULL.

Btw, a 1:1 relationship is only possible if: 1) the relationship is between two PK's OR 2) the relationship has a UC on the FK fields. If the fields are nullable makes no difference.

Posts: 56
Joined: 08-Jun-2010
# Posted on: 25-Oct-2010 17:23:52   

Thanks for getting back so quickly!

I'm using sqlserver, llblgen knows I'm using sqlserver. Llblgen actively tells me I need to run this ddl script - I don't think it should do that if the script it gens is not supported on my db.

I'm not sure what you're telling me about the 1:1 relationship? I have a ParentTable which has a FK to ChildTable (The FK is not in the database due to nulls). The FK is either null or represents the PK on ChildTable and will be mostly null. I cannot set up a UC due to the nulls. this is 1 to 0:1. are you saying this is not supported confused

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39888
Joined: 17-Aug-2003
# Posted on: 25-Oct-2010 18:43:32   

Please give more information about your particular problem, as it will otherwise take a lot of time. So please specify in detail your relationship, what you get and what you want.

For a 1:1 relationship to exist, it HAS to have a UC on the Fk fields, otherwise it's a 1:n relationship. So if you want to store a lot of null values in the field, you can't have a UC on the field in SQL Server. You can create the tables with DDL SQL just fine, it just won't accept more than 1 null. So what we generate is actually OK, the problem is: there's no other way to create a 1:1 relationship, as without a UC, the relationship is a 1:n: there's no way you're prevented to store multiple times the same fk value in the fk field as there's no UC on the field.

Reverse engineering such a relationship (FK constraint) will always result in a 1:n and therefore the UC is mandatory.

Frans Bouma | Lead developer LLBLGen Pro