The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TeknikEntities.cs 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Microsoft.AspNet.Identity.EntityFramework;
  2. using System.Data.Entity;
  3. using System.Data.Entity.Infrastructure;
  4. using Teknik.Areas.Blog.Models;
  5. using Teknik.Areas.Profile.Models;
  6. using Teknik.Areas.Contact.Models;
  7. using Teknik.Migrations;
  8. using Teknik.Areas.Upload.Models;
  9. using Teknik.Areas.Paste.Models;
  10. using Teknik.Areas.Podcast.Models;
  11. using Teknik.Areas.Transparency.Models;
  12. namespace Teknik.Models
  13. {
  14. public class TeknikEntities : DbContext
  15. {
  16. // Users
  17. public DbSet<User> Users { get; set; }
  18. public DbSet<Group> Groups { get; set; }
  19. public DbSet<Role> Roles { get; set; }
  20. // User Settings
  21. public DbSet<UserSettings> UserSettings { get; set; }
  22. public DbSet<BlogSettings> BlogSettings { get; set; }
  23. public DbSet<UploadSettings> UploadSettings { get; set; }
  24. // Blogs
  25. public DbSet<Blog> Blogs { get; set; }
  26. public DbSet<BlogPost> BlogPosts { get; set; }
  27. public DbSet<BlogPostComment> BlogComments { get; set; }
  28. // Contact
  29. public DbSet<Contact> Contact { get; set; }
  30. // Uploads
  31. public DbSet<Upload> Uploads { get; set; }
  32. // Pastes
  33. public DbSet<Paste> Pastes { get; set; }
  34. // Podcasts
  35. public DbSet<Podcast> Podcasts { get; set; }
  36. public DbSet<PodcastFile> PodcastFiles { get; set; }
  37. public DbSet<PodcastComment> PodcastComments { get; set; }
  38. // Transparency
  39. public DbSet<Transaction> Transactions { get; set; }
  40. public DbSet<Takedown> Takedowns { get; set; }
  41. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  42. {
  43. // User Settings Mappings
  44. modelBuilder.Entity<User>()
  45. .HasRequired(a => a.UserSettings)
  46. .WithRequiredPrincipal(a => a.User);
  47. modelBuilder.Entity<User>()
  48. .HasRequired(a => a.BlogSettings)
  49. .WithRequiredPrincipal(a => a.User);
  50. modelBuilder.Entity<User>()
  51. .HasRequired(a => a.UploadSettings)
  52. .WithRequiredPrincipal(a => a.User);
  53. modelBuilder.Entity<UserSettings>()
  54. .HasRequired(a => a.BlogSettings)
  55. .WithRequiredPrincipal(a => a.UserSettings);
  56. modelBuilder.Entity<UserSettings>()
  57. .HasRequired(a => a.UploadSettings)
  58. .WithRequiredPrincipal(a => a.UserSettings);
  59. modelBuilder.Entity<BlogSettings>()
  60. .HasRequired(a => a.UploadSettings)
  61. .WithRequiredPrincipal(a => a.BlogSettings);
  62. // User Mappings
  63. modelBuilder.Entity<User>()
  64. .HasMany<Upload>(u => u.Uploads)
  65. .WithOptional(u => u.User)
  66. .WillCascadeOnDelete(false);
  67. modelBuilder.Entity<User>()
  68. .HasMany<Paste>(u => u.Pastes)
  69. .WithOptional(u => u.User)
  70. .WillCascadeOnDelete(false);
  71. // Upload Mappings
  72. modelBuilder.Entity<Upload>()
  73. .HasOptional(u => u.User);
  74. // Paste Mappings
  75. modelBuilder.Entity<Paste>()
  76. .HasOptional(u => u.User);
  77. // Users
  78. modelBuilder.Entity<User>().ToTable("Users");
  79. modelBuilder.Entity<Group>().ToTable("Groups");
  80. modelBuilder.Entity<Role>().ToTable("Roles");
  81. // User Settings
  82. modelBuilder.Entity<UserSettings>().ToTable("Users");
  83. modelBuilder.Entity<BlogSettings>().ToTable("Users");
  84. modelBuilder.Entity<UploadSettings>().ToTable("Users");
  85. // Blogs
  86. modelBuilder.Entity<Blog>().ToTable("Blogs");
  87. modelBuilder.Entity<BlogPost>().ToTable("BlogPosts");
  88. modelBuilder.Entity<PodcastComment>().ToTable("BlogComments");
  89. // Contact
  90. modelBuilder.Entity<Contact>().ToTable("Contact");
  91. // Uploads
  92. modelBuilder.Entity<Upload>().ToTable("Uploads");
  93. // Pastes
  94. modelBuilder.Entity<Paste>().ToTable("Pastes");
  95. // Podcasts
  96. modelBuilder.Entity<Podcast>().ToTable("Podcasts");
  97. modelBuilder.Entity<PodcastFile>().ToTable("PodcastFiles");
  98. modelBuilder.Entity<PodcastComment>().ToTable("PodcastComments");
  99. // Transparency
  100. modelBuilder.Entity<Transaction>().ToTable("Transactions");
  101. modelBuilder.Entity<Takedown>().ToTable("Takedowns");
  102. base.OnModelCreating(modelBuilder);
  103. }
  104. }
  105. }