Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. using AnrixNetwork.Models;
  2. using AnrixReborn.Models;
  3. using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
  4. using Microsoft.EntityFrameworkCore;
  5. using static AnrixReborn.Areas.Identity.Pages.Account.RegisterModel;
  6.  
  7. namespace AnrixReborn.Data
  8. {
  9. public class ApplicationDbContext : IdentityDbContext<AnrixUser>
  10. {
  11. public DbSet<Dialog> Dialogs { get; set; }
  12. public DbSet<Message> Messages { get; set; }
  13.  
  14. public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
  15. : base(options)
  16. {
  17. }
  18. protected override void OnModelCreating(ModelBuilder modelBuilder)
  19. {
  20. base.OnModelCreating(modelBuilder);
  21.  
  22. modelBuilder.Entity<UserDialog>()
  23. .HasKey(bc => new { bc.UserId, bc.DialogId });
  24.  
  25. modelBuilder.Entity<UserDialog>()
  26. .HasOne(bc => bc.User)
  27. .WithMany(b => b.UserDialogs)
  28. .HasForeignKey(bc => bc.UserId);
  29.  
  30. modelBuilder.Entity<UserDialog>()
  31. .HasOne(bc => bc.Dialog)
  32. .WithMany(c => c.UserDialogs)
  33. .HasForeignKey(bc => bc.DialogId);
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement