我想創建基業爲使用SQL Server在C#對象,我有:SQL中的繼承。如何保證它?
create table dbo.Evaluations
(
Id int not null constraint primary key clustered (Id),
Created datetime not null
);
create table dbo.Exams
(
Id int not null,
Value int not null
// Some other fields
);
create table dbo.Tests
(
Id int not null,
Order int not null
// Some other fields
);
alter table dbo.Exams
add constraint FK_Exams_Id foreign key (Id) references dbo.Evaluations(Id);
alter table dbo.Tests
add constraint FK_Tests_Id foreign key (Id) references dbo.Evaluations(Id);
這將轉化爲:
public class Evaluation {}
public class Exam : Evaluation {}
public class Test : Evaluation {}
我認爲這是去,但我有辦法問題:
如何強制,一個
Evaluation
只有一個Test
或一個Exam
但不是機器人H?要找到我有哪種類型的評估,我可以檢查考試或測試null。但是,我應該有表中的
EvaluationType
嗎?
注: 在現實中,我有4個亞型每一個與大約40到60個不同的列。 而在評估表中,我有大約20個常用列,這些列也是我經常用來查詢的列,所以我列出了列表。
http://stackoverflow.com/questions/386652/techniques-for-database-inheritance – Donal 2014-09-01 14:29:24
是的,我已經讀過......但我不知道如何回答我的2個問題......我應該使用2個表格,考試和考試,並將共同的列放入其中?事實上,我有兩個對象和大約15個共同的列,所以我雖然這是要走的路。 – 2014-09-01 14:33:31
我會和戈登一起回答 – Donal 2014-09-01 14:35:19