dragonwell
Programmer
I have been trying to base my data-models (tables and relations) on my domain model (classes, subclasses, interfaces etc.). So far I think it has helped.
I find that having one table per class makes the most sense, even if it means more query-joins.
Now I have just noticed something. I can map my inheritance in one of two ways.
Example:
Abstract Class Event.
Concrete Class Meeting, Inherits Event.
Method 1
Method 2
The only difference is that in method two, the primary key from the root class table is also used as the primary key if the derived table class (since it's a 1:1 relationship anyway).
I would like to hear anyone's opinions on this - what is better, why, etc.
Thanks!
I find that having one table per class makes the most sense, even if it means more query-joins.
Now I have just noticed something. I can map my inheritance in one of two ways.
Example:
Abstract Class Event.
Concrete Class Meeting, Inherits Event.
Method 1
Code:
CREATE TABLE Event(
EventID int identity, --PK
EventDate datetime
)
CREATE TABLE Meeting(
MeetingID int identity,--PK
EventID int, --FK
Location varchar(50)
)
Method 2
Code:
CREATE TABLE Event(
EventID int identity, --PK
EventDate datetime,
)
CREATE TABLE Meeting(
EventID int, --PK, FK
Location varchar(50)
)
The only difference is that in method two, the primary key from the root class table is also used as the primary key if the derived table class (since it's a 1:1 relationship anyway).
I would like to hear anyone's opinions on this - what is better, why, etc.
Thanks!