views:

37

answers:

1

Trying to setup a simple Thread/Poll table mapping.

Here is what I have:

Threads table

  • ThreadID (Primary Key/Identity Column)

Polls table

  • PollID (Primary Key, FK for ThreadID for one-to-one relation)
  • Question

PollOptions table

  • PollOptionID (Identity/Primary Key)
  • Text
  • PollID

PollVotes table

  • PollVoteID (Primary Key/Identity)
  • PollOptionID

I'm not sure if this is a proper relationship. It seems wrong but I'm not sure whats wrong with it.

A Thread can have 0 or 1 Poll.

A Poll can have 2 or more PollOptions.

A PollOption can have 0 or many PollVotes.

I'm going to be using Entity Framework and before I generate the code for it (VS 2010, .NET 4) I want to make sure I have the proper relationship mapping.

+1  A: 

Maybe I'm misreading your relation there, but it seems like relating Poll to Thread would make more sense than Thread to Poll, since you have a 0 or 1 relationship with Thread to Poll. Otherwise I think your relationships look fine.

Myles
But a Poll is a child of Thread (somewhat). A Poll can only be created for a Thread, a thread can be created without a poll.
Baddie
Right, which is why the Poll should hold the ID to the Thread. Eg:Thread Table:ThreadIdPoll Table:PollIdThreadId
Myles