obzekt wrote:
Hello. From what I understood LLBLGen supports both types of 1:1 setups. What is the recommended approach in theory and in practice with LLBLGen?
1:1 relations can be the following:
A and B have a 1:1 relation if:
- PK of A has a relation with PK of B and B is then an FK. Example: Person and Customer
- PK of A has a relation with field(s) in B which form an FK pointing to PK of A and are not part of the PK and have a unique constraint applied to them. Example: AddressID in Customer, pointing to AddressID in Address and Customer.AddressID has a unique constraint.
so if you want 1:1 relationships, you should setup your relational model like I described above.
For example, if I have Order and OrderDetails, what is best:
1. Use OrderID as PK to both tables (identity in Order and FK in OrderDetails).
2. Use OrderDetailsID identity PK (for consistency with the rest of the schema that uses identity keys everywhere) and add a unique constraint on OrderID FK.
Order and OrderDetail do not have a 1:1 relation but a 1:n relation, IF each order has just 1 orderdetail record. If more than 1 orderdetail record can be in 1 order, it's a 1:n relation from Order -> OrderDetail and a m:1 relation from OrderDetail -> Order.
An OrderDetail record has to be uniquely identifyable, and if an order has more than 1 orderdetail (what's most of the time is the case) 1) will not be sufficient.
2) is the best solution, however forget the UC on OrderID if you want to have more order detail records in an order. I'm not sure if that's the case in your situation.