0

I am migrating my project from Entity Framework to EF Core 6 but now I am stuck at this point.

modelBuilder.Entity<tblStoreGroup>()
            .HasMany(e => e.tblUsers)
            .WithMany(e => e.tblStoreGroups)
            .Map(m => m.ToTable("tblBridgeUserGroup")
                       .MapLeftKey("GroupID")
                       .MapRightKey("username"));

Because the Map() property is not available in EF Core, can someone please provide a solution for this code?

I am a beginner in Entity Framework.

Thanks in advance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Fahad Mughal
  • 101
  • 9

1 Answers1

1

You can try using UsingEntity:

modelBuilder.Entity<tblStoreGroup>()
    .HasMany(p => p.tblUsers)
    .WithMany(p => p.tblStoreGroups)
    .UsingEntity<Dictionary<string, object>>(
        "tblBridgeUserGroup",
        j => j
            .HasOne<tblUser>()
            .WithMany()
            .HasForeignKey("username"),
        j => j
            .HasOne<tblStoreGroup>()
            .WithMany()
            .HasForeignKey("GroupID"));

See Joining relationships configuration section of the docs.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132