Question

i have one transaction table, each transaction has 5-6 contacts involved. each contact has the same fields like name, address, cell, email etc.

So the best thing I guess is to use the same contact table and relate it 5 times to the transaction table.. So I don't need to make the same kind of table 5 times.

The problem starts when I connect with the entity-framework this only takes one relation.

My question is should I make 6 copies of contact for each contact type or I would be better with 6 join tables (A table with just the 2 id's so I could do a join)?

I think its a very common problem but I couldn't find clear information what the best way is.

EDIT: Sample of Tables

Was it helpful?

Solution

The best thing is to normalize the tables. Create a contact_type table with a record for each contact type. Then create a contact_type_xref junction table that contains the identifier from the contact table and the identifier from the contact_type table. Then load the contact types associated to each contact into the contact_type_xref, and remove the duplicate contact records from contact. Here's an example:Schema Example. Once you fix the database design, you can tackle the entity-framework problem (which will probably disappear).

OTHER TIPS

First off, it's a bit of a rubbish framework that doesn't acknowledge multiple relationships between entity types!

If you have this many foreign keys, chances are you'll have more (or fewer) in the future. The solution @Wil details will allow you achieve this without schema changes.

One work-around which may fool your framework would be to define views in the database for each of your contact types and define framework relationship from transaction to the view. For example

create view Manufacture as
select
    ContactID as ManufactureID,
    FirstName,
    LastName,
    ...etc.
from Contacts

May or may not work, depending on how your framework interacts with the database.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top