BOContext.decl.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Microsoft.EntityFrameworkCore;
  2. namespace BO.AppServer.Data.Entity
  3. {
  4. public partial class BOContext
  5. {
  6. partial void OnModelCreatingPartial(ModelBuilder modelBuilder)
  7. {
  8. modelBuilder.Entity<Workspace>(entity =>
  9. {
  10. // WORKAROUND temporary solution for keyless entity
  11. //modelBuilder.Entity<UserWorkspace>()
  12. // .HasAlternateKey(x => x.Id);
  13. modelBuilder.Entity<UserWorkspace>()
  14. .HasKey(t => new { t.WorkspaceId, t.UserId });
  15. modelBuilder.Entity<UserWorkspace>()
  16. .HasOne(am => am.User)
  17. .WithMany(a => a.UserWorkspaces)
  18. .HasForeignKey(am => am.UserId);
  19. modelBuilder.Entity<UserWorkspace>()
  20. .HasOne(am => am.Workspace)
  21. .WithMany(m => m.UserWorkspaces)
  22. .HasForeignKey(am => am.WorkspaceId);
  23. modelBuilder.Entity<Workspace>().HasOne(d => d.BillingInfo)
  24. .WithOne(p => p.Workspace)
  25. .OnDelete(DeleteBehavior.ClientSetNull)
  26. .HasConstraintName("REL_Workspace_BillingInfo");
  27. }
  28. );
  29. }
  30. }
  31. }