One-to-many relationship related to many tables

Posted by Andrey on Stack Overflow See other posts from Stack Overflow or by Andrey
Published on 2010-05-20T20:13:09Z Indexed on 2010/05/20 20:30 UTC
Read the original article Hit count: 170

Filed under:
|

I have a scenario where: there are two (or more) tables that represent independent items. lets say Users and Companies

Both of these tables need addresses stored. Each one can have one or more address

In a normal 1 to many scenario Addresses table woudl just have a UserId or a CompanyId creating a normal 1 to many relationship.

In this case i have a few approaches i can think of

  1. the Addresses table could have both a UserId and a CompanyId and only one would be used for each record.

  2. 2 keys could be used ObjectId and ObjectType So Object id would have a UserId or a CompanyId, and ObjectType woudl be User or Company

  3. Create an ObjectTable and add ObjectId to Users and Companies. Addresses would then have an OjbectId

I do not really like any of these solutions. i am wondering what is the best approach here.

On another note i will most likely user linqtosql for my data access layer.

© Stack Overflow or respective owner

Related posts about sql

Related posts about linq-to-sql