Hello there,
This questions is perhaps not in the right spot but it is the closest spot to put it I guess.
Take for example the following entities
- Client
- Attachment (This is a scanned file such as a copy of a drivers liscence)
- Sale
- Service Order
The relations are as follows
- A Client has a sale
- A Client has a Service Order
- A Client has an attachment
- A Sale has an Attachment
- A ServiceOrder has an Attachment
How would one typically setup the table structure that is best suited for LLBLGEN? The way I would normally do it is as follows in option 1.
OPTION 1 (This is the most normalised most extensible way I believe)
Attachment
- attachmentId (pk)
- blobdata
- otherAttachmentFields
- etc
Client
- clientId (pk)
- etc
ClientAttachment (This is just a M:M link table)
- clientId (pk)
- attachmentId (pk)
Sale
- SaleId (pk)
- etc
SaleAttachment (This is just a M:M link table)
- saleId (pk)
- attachmentId (pk)
The advantage of this approach is that the Attachment table structures are not repeated. It is the most extensible method as well.
The disadvantages is all the joins necessary which are a pain in the ass in which case I would consider Option 2 probably a better approach.
Would LLBLGEN like this approach?
OPTION 2
Client
- clientId (pk)
- etc
ClientAttachment
- ClientAttachmentId (pk)
- clientId
- blobdata
- etc
Sale
- SaleId (pk)
- etc
SaleAttachment
- saleAttachmentId (pk)
- saleId
- blobdata
- etc
This seems easier because there is less joins as I am ommiting the link tables, but it comes at the expense of maintenance (ie, updating different tables with the same schema).
This is how adventureworks does most things im pretty sure.
OPTION 3
Denormalise
Have the following tables
Client
- ClientID (pk)
Sale
- SaleId (pk)
Attachment
- attachmentId (pk)
- linkId (Different foreign key depending on the linkType)
- LinkType (ClientAttachment, SaleAttachment, ServiceOrderAttachment, etc)
- AttachmentBlob (The blob Data)
This is dodgy and I dont like it.
I have attached an image of the layout of Option 1 and Option 2.
Thank you kindly for any advice