Mapping Friendship in dotnet (and many to many relations entity framework core)

public class PersonsDbContext : DbContext
{
public DbSet<Person> Persons { get; init; } = null!;

public PersonsDbContext(DbContextOptions<PersonsDbContext> dbContextOptions): base(dbContextOptions)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var navigation = modelBuilder.Entity<Person>().Metadata.FindNavigation(nameof(Person.AllFriends))!;
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
navigation.SetField("_allFriends");
base.OnModelCreating(modelBuilder);
}
}

--

--

--

Software consultant

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

An Overview of chef

Introduction to Big Data with Spark and Hadoop - Week 1. What is Big Data?

Make it right, make it work with JavaScript.

Top 10 Resources To Learn Coding Free

Exploring Java #2: Try-With-Resources

What can we learn from Automation Testing failures?

UML Use Case Diagram

Locking mechanisms in iOS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prashant Choudhary

Prashant Choudhary

Software consultant

More from Medium

Scan SonarQube branches and pull request branches without paid licenses

Blazor Server App to MS Teams messaging

Creating a Linux VM with startup script in Azure(2/2)

Address confirmation via Google/Serpapi