For faster navigation, this Iframe is preloading the Wikiwand page for Розмітка зв'язків таблиць (шаблон проєктування).

Розмітка зв'язків таблиць (шаблон проєктування)

Матеріал з Вікіпедії — вільної енциклопедії.

Розмітка зв'язків таблиць (англ. Association Table Mapping) — шаблон проєктування, який пропонує відображати колекції об'єктів у вигляді проміжних таблиць з зовнішніми ключами.

Об'єкти із легкістю можуть містити набір значень у вигляді колекцій. Реляційні бази обмежуються полями з одним значенням. При відношенні "один до багатьох" можна використати розмітку зовнішніх ключів. Але при відношенні "багато до багатьох" немає однозначної сутності на яку би посилався зовнішній ключ.

Рішення таке ж як і в реляційних базах даних — створення проміжної сутності, яка міститиме ключі.

Реалізація

[ред. | ред. код]

Нехай дані об'єкти, які представляють моделі таблиць у сховищі.

class EmployeeTable
{
        public int Id { get; set; }
        public string Name { get; set; }
}

class SkillTable
{
        public int Id { get; set; }
        public string Name { get; set; }
}

class EmployeeSkillTable
{
        public int EmployeeId { get; set; }
        public int SkillId { get; set; }
}

Тоді у пам'яті таку структуру можна описати наступним чином. Правда в такому випадку ускладнюється логіка відображення об'єктів у моделі даних.

class Employee
{
        public int Id { get; set; }
        public string Name { get; set; }

        public ICollection<Skill> Skills { get; set; }
}

class Skill
{
        public int Id { get; set; }
        public string Name { get; set; }

        public ICollection<Employee> Employees { get; set; }
}

Або згідно шаблону.

class Employee
{
        public int Id { get; set; }
        public string Name { get; set; }

        public ICollection<EmployeeSkill> Skills { get; set; }
}

class Skill
{
        public int Id { get; set; }
        public string Name { get; set; }

        public ICollection<EmployeeSkill> Employees { get; set; }
}

class EmployeeSkill
{
        public int EmployeeId { get; set; }
        public int SkillId { get; set; }
}

Див. також

[ред. | ред. код]

Джерела

[ред. | ред. код]
{{bottomLinkPreText}} {{bottomLinkText}}
Розмітка зв'язків таблиць (шаблон проєктування)
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?