Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ManyToMany docs #424

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions docs/modeling/model-components/attributes/many-to-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ViewModel.
The named specified in the attribute will be used as the name of a collection of the objects on the other side of the relationship in the generated [TypeScript ViewModels](/stacks/disambiguation/view-model.md).

## Example Usage

In this example, we have a Person entity and an Appointment entity that share a many-to-many relationship. The PersonAppointment entity serves as the required middle table.
``` c#
public class Person
{
Expand All @@ -22,6 +22,26 @@ public class Person
[ManyToMany("Appointments")]
public ICollection<PersonAppointment> PersonAppointments { get; set; }
}

public class Appointment
{
public int AppointmentId { get; set; }
public DateTime AppointmentDate { get; set; }

[ManyToMany("People")]
public ICollection<PersonAppointment> PersonAppointments { get; set; }
}

public class PersonAppointment
{
public int PersonAppointmentId { get; set; }

public int PersonId { get; set; }
public Person Person { get; set; }

public int AppointmentId { get; set; }
public Appointment Appointment { get; set; }
}
```

## Properties
Expand All @@ -33,4 +53,32 @@ The name of the collection that will contain the set of objects on the other sid

<Prop def="public string FarNavigationProperty { get; set; }" />

The name of the navigation property on the middle entity that points at the far side of the many-to-many relationship. Use this to resolve ambiguities when the middle table of the many-to-many relationship has more than two reference navigation properties on it.
The name of the navigation property on the middle entity that points at the far side of the many-to-many relationship. Use this to resolve ambiguities when the middle table of the many-to-many relationship has more than two reference navigation properties on it.

``` c#
public class Person
{
...

[ManyToMany("Appointments", FarNavigationProperty = nameof(PersonAppointment.Appointment))]
public ICollection<PersonAppointment> PersonAppointments { get; set; }
}

public class Appointment
{
...

[ManyToMany("People", FarNavigationProperty = nameof(PersonAppointment.Person))]
public ICollection<PersonAppointment> PersonAppointments { get; set; }
}

public class PersonAppointment
{
...

// Adding a third reference navigation property in the middle table requires
// the use of FarNavigationProperty in order to resolve ambiguity.
public int WaiverId { get; set; }
public Waiver Waiver { get; set; }
}
```
Loading