3.5 建立模型-關係
阿新 • • 發佈:2020-07-22
術語定義
有許多術語用於描述關係
- 相關實體: 這是包含外來鍵屬性的實體。 有時稱為關係的 "子級"。
- 主體實體: 這是包含主/備用鍵屬性的實體。 有時稱為關係的 "父項"。
- 主體金鑰: 唯一標識主體實體的屬性。 這可能是主鍵或備用金鑰。
- 外來鍵: 用於儲存相關實體的主體鍵值的依賴實體中的屬性。
- 導航屬性: 在主體和/或從屬實體上定義的屬性,該屬性引用相關實體。
- 集合導航屬性: 一個導航屬性,其中包含對多個相關實體的引用。
- 引用導航屬性: 儲存對單個相關實體的引用的導航屬性。
- 反向導航屬性: 討論特定導航屬性時,此術語是指關係另一端的導航屬性。
- 自引用關係: 依賴關係和主體實體型別相同的關係。
下面的程式碼顯示與之間的一對多關係 Blog``Post
public class Blog { public int BlogId { get; set; } public string Url { get; set; } public List<Post> Posts { get; set; } } public class Post { public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public int BlogId { get; set; } public Blog Blog { get; set; } }
Post
是依賴實體Blog
是主體實體Blog.BlogId
是主體鍵(在本例中為主金鑰,而不是備用金鑰)Post.BlogId
為外來鍵Post.Blog
是一個引用導航屬性Blog.Posts
是集合導航屬性Post.Blog
是的反向導航屬性Blog.Posts
(反之亦然)