Entity Framework Map() property alternate in EF Core 6

255 Views Asked by At

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

1

There are 1 best solutions below

0
Guru Stron On

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.