With the code below, Npgsql generates the following join entity:
EntityType: FruitJam (Dictionary<string, object>) CLR Type: Dictionary<string, object>
Properties:
FruitsId (no field, Guid) Indexer Required PK FK AfterSave:Throw
JamsId (no field, Guid) Indexer Required PK FK Index AfterSave:Throw
Keys:
FruitsId, JamsId PK
Foreign keys:
FruitJam (Dictionary<string, object>) {'FruitsId'} -> Fruit {'Id'} Required Cascade
FruitJam (Dictionary<string, object>) {'JamsId'} -> Jam {'Id'} Required Cascade
Indexes:
JamsId
With the same code, the Mongo provider generates:
EntityType: FruitJam (Dictionary<string, object>) CLR Type: Dictionary<string, object>
Properties:
FruitsId (no field, Guid) Indexer Required PK AfterSave:Throw ValueGenerated.OnAdd
FruitsId1 (no field, Guid) Indexer Required FK Index
JamsId (no field, Guid) Indexer Required FK Index
Keys:
FruitsId PK
Foreign keys:
FruitJam (Dictionary<string, object>) {'FruitsId1'} -> Fruit {'Id'} Required Cascade
FruitJam (Dictionary<string, object>) {'JamsId'} -> Jam {'Id'} Required Cascade
Indexes:
FruitsId1 FruitsId1_1
JamsId JamsId_1
"FruitsId1" should not be present in the model.
Repro:
await using var db = new DbPreserves(); Console.WriteLine(db.Model.ToDebugString()); public class DbPreserves : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseMongoDB("mongodb://localhost:56668/?directConnection=true", "Fruity5"); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Jam>().HasMany(e => e.Fruits).WithMany(e => e.Jams); } } public class Fruit { public Guid Id { get; set; } public string Name { get; set; } = null!; public List<Jam> Jams { get; } = new(); } public class Jam { public Guid Id { get; set; } public string Name { get; set; } = null!; public List<Fruit> Fruits { get; } = new(); }