using Microsoft.EntityFrameworkCore; namespace BO.AppServer.Data.Entity { public partial class BOContext { partial void OnModelCreatingPartial(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { // WORKAROUND temporary solution for keyless entity //modelBuilder.Entity() // .HasAlternateKey(x => x.Id); modelBuilder.Entity() .HasKey(t => new { t.WorkspaceId, t.UserId }); modelBuilder.Entity() .HasOne(am => am.User) .WithMany(a => a.UserWorkspaces) .HasForeignKey(am => am.UserId).HasConstraintName("REL_BillingInfo_User"); modelBuilder.Entity() .HasOne(am => am.Workspace) .WithMany(m => m.UserWorkspaces) .HasForeignKey(am => am.WorkspaceId).HasConstraintName("REL_BillingInfo_Workspace"); //modelBuilder.Entity().Metadata.AddIgnored("Workspace"); modelBuilder.Entity().HasOne(d => d.BillingInfo) .WithOne(p => p.Workspace) .HasForeignKey(a => a.WorkspaceId) .OnDelete(DeleteBehavior.NoAction) .HasConstraintName("REL_Workspace_BillingInfo"); modelBuilder.Entity().HasMany(w=>w.Structures) .WithOne(s => s.Workspace) .HasForeignKey(s => s.WorkspaceId) .HasConstraintName("REL_Structure_Workspace"); modelBuilder.Entity().Navigation(w => w.Structures).AutoInclude(); modelBuilder.Entity().Navigation(w => w.CreatedByUser).AutoInclude(); modelBuilder.Entity().Navigation(w => w.ModifiedByUser).AutoInclude(); modelBuilder.Entity().Navigation(w => w.Metadocuments).AutoInclude(); modelBuilder.Entity().HasOne(d => d.CreatedByUser) .WithMany(p => p.StructureCreatedByUsers) .HasForeignKey(d => d.CreatedByUserId) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("REL_Structure_User_Created"); modelBuilder.Entity().HasOne(d => d.ModifiedByUser) .WithMany(p => p.StructureModifiedByUsers) .HasForeignKey(d => d.ModifiedByUserId) .HasConstraintName("REL_Structure_User_Modified"); modelBuilder.Entity().Navigation(w => w.CreatedByUser).AutoInclude(); modelBuilder.Entity().Navigation(w => w.ModifiedByUser).AutoInclude(); modelBuilder.Entity().Navigation(w => w.CreatedByUser).AutoInclude(); modelBuilder.Entity().Navigation(w => w.CreatedByUser).AutoInclude(); modelBuilder.Entity().Navigation(w => w.ModifiedByUser).AutoInclude(); modelBuilder.Entity().Navigation(w => w.CreatedByUser).AutoInclude(); modelBuilder.Entity().Navigation(w => w.ModifiedByUser).AutoInclude(); } ); } } }