Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.05 KB | None | 0 0
  1. public class ApplicationUser : IdentityUser
  2. {
  3. public string BusinessName { get; set; }
  4. public string ContactName { get; set; }
  5. public string CountryCode { get; set; }
  6. public virtual Countries Country { get; set; }
  7. public string AddressLabel { get; set; }
  8. public string Phone { get; set; }
  9. public DateTime? FollowUp { get; set; }
  10. public bool MailingList { get; set; }
  11. public int SubscriptionId { get; set; }
  12. [ForeignKey("SubscriptionId")]
  13. public virtual Subscriptions Subscription { get; set; }
  14. public virtual ICollection<Devices> Devices { get; set; }
  15. public virtual ICollection<Downloads> Downloads { get; set; }
  16. public virtual ICollection<Invoices> Invoices { get; set; }
  17. public virtual ICollection<Notes> Notes { get; set; }
  18. public virtual ICollection<Referrals> Referrals { get; set; }
  19. }
  20.  
  21. public partial class CustomersContext : IdentityDbContext<ApplicationUser>
  22. {
  23. protected override void OnConfiguring(DbContextOptionsBuilder options)
  24. {
  25. options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Customers;Trusted_Connection=True;MultipleActiveResultSets=true");
  26. }
  27.  
  28. protected override void OnModelCreating(ModelBuilder modelBuilder)
  29. {
  30. base.OnModelCreating(modelBuilder);// we have to do this becauee we are inheriting from IdentityDbContext<ApplicationUser> not DbContext
  31. modelBuilder.Entity<AspNetRoleClaims>(entity =>
  32. {
  33. entity.Property(e => e.RoleId).HasMaxLength(450);
  34.  
  35. entity.HasOne(d => d.Role).WithMany(p => p.AspNetRoleClaims).HasForeignKey(d => d.RoleId);
  36. });
  37.  
  38. modelBuilder.Entity<AspNetRoles>(entity =>
  39. {
  40. entity.HasIndex(e => e.NormalizedName).HasName("RoleNameIndex");
  41.  
  42. entity.Property(e => e.Id).HasMaxLength(450);
  43.  
  44. entity.Property(e => e.Name).HasMaxLength(256);
  45.  
  46. entity.Property(e => e.NormalizedName).HasMaxLength(256);
  47. });
  48.  
  49. modelBuilder.Entity<AspNetUserClaims>(entity =>
  50. {
  51. entity.Property(e => e.UserId).HasMaxLength(450);
  52.  
  53. entity.HasOne(d => d.User).WithMany(p => p.AspNetUserClaims).HasForeignKey(d => d.UserId);
  54. });
  55.  
  56. modelBuilder.Entity<AspNetUserLogins>(entity =>
  57. {
  58. entity.HasKey(e => new { e.LoginProvider, e.ProviderKey });
  59.  
  60. entity.Property(e => e.LoginProvider).HasMaxLength(450);
  61.  
  62. entity.Property(e => e.ProviderKey).HasMaxLength(450);
  63.  
  64. entity.Property(e => e.UserId).HasMaxLength(450);
  65.  
  66. entity.HasOne(d => d.User).WithMany(p => p.AspNetUserLogins).HasForeignKey(d => d.UserId);
  67. });
  68.  
  69. modelBuilder.Entity<AspNetUserRoles>(entity =>
  70. {
  71. entity.HasKey(e => new { e.UserId, e.RoleId });
  72.  
  73. entity.Property(e => e.UserId).HasMaxLength(450);
  74.  
  75. entity.Property(e => e.RoleId).HasMaxLength(450);
  76.  
  77. entity.HasOne(d => d.Role).WithMany(p => p.AspNetUserRoles).HasForeignKey(d => d.RoleId).OnDelete(DeleteBehavior.Restrict);
  78.  
  79. entity.HasOne(d => d.User).WithMany(p => p.AspNetUserRoles).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  80. });
  81.  
  82. modelBuilder.Entity<ApplicationUser>(entity =>
  83. {
  84. entity.HasIndex(e => e.BusinessName).HasName("BusinessNameIndex");
  85.  
  86. entity.HasIndex(e => e.NormalizedEmail).HasName("EmailIndex");
  87.  
  88. entity.HasIndex(e => e.NormalizedUserName).HasName("UserNameIndex");
  89.  
  90. entity.Property(e => e.Id).HasMaxLength(450);
  91.  
  92. entity.Property(e => e.AddressLabel)
  93. .HasMaxLength(255)
  94. .HasColumnType("varchar");
  95.  
  96. entity.Property(e => e.BusinessName)
  97. .HasMaxLength(255)
  98. .HasColumnType("varchar");
  99.  
  100. entity.Property(e => e.ContactName)
  101. .HasMaxLength(255)
  102. .HasColumnType("varchar");
  103.  
  104. entity.Property(e => e.CountryCode)
  105. .IsRequired()
  106. .HasMaxLength(2)
  107. .HasColumnType("varchar")
  108. .HasDefaultValue("00");
  109.  
  110. entity.Property(e => e.Email).HasMaxLength(256);
  111.  
  112. entity.Property(e => e.FollowUp).HasColumnType("date");
  113.  
  114. entity.Property(e => e.MailingList).HasDefaultValue(true);
  115.  
  116. entity.Property(e => e.NormalizedEmail).HasMaxLength(256);
  117.  
  118. entity.Property(e => e.NormalizedUserName).HasMaxLength(256);
  119.  
  120. entity.Property(e => e.UserName).HasMaxLength(256);
  121.  
  122. entity.HasOne(d => d.Country).WithMany(p => p.Users).HasForeignKey(d => d.CountryCode).OnDelete(DeleteBehavior.Restrict);
  123.  
  124. entity.HasOne(d => d.Subscription).WithMany(p => p.Users).HasForeignKey(d => d.SubscriptionId).OnDelete(DeleteBehavior.Restrict);
  125. });
  126.  
  127. modelBuilder.Entity<Countries>(entity =>
  128. {
  129. entity.HasKey(e => e.CountryCode);
  130.  
  131. entity.Property(e => e.CountryCode)
  132. .HasMaxLength(2)
  133. .HasColumnType("varchar");
  134.  
  135. entity.Property(e => e.CalCost).HasColumnType("decimal");
  136.  
  137. entity.Property(e => e.CountryName)
  138. .IsRequired()
  139. .HasMaxLength(50)
  140. .HasColumnType("varchar");
  141.  
  142. entity.Property(e => e.CultureCode)
  143. .IsRequired()
  144. .HasMaxLength(8)
  145. .HasColumnType("varchar");
  146.  
  147. entity.Property(e => e.CurrencyCode)
  148. .IsRequired()
  149. .HasMaxLength(3)
  150. .HasColumnType("varchar");
  151.  
  152. entity.Property(e => e.InvoiceFooter)
  153. .HasMaxLength(50)
  154. .HasColumnType("varchar");
  155.  
  156. entity.Property(e => e.InvoiceName)
  157. .IsRequired()
  158. .HasMaxLength(50)
  159. .HasColumnType("varchar");
  160.  
  161. entity.Property(e => e.TaxName)
  162. .HasMaxLength(3)
  163. .HasColumnType("varchar");
  164.  
  165. entity.Property(e => e.TaxRate).HasColumnType("decimal");
  166. });
  167.  
  168. modelBuilder.Entity<Devices>(entity =>
  169. {
  170. entity.HasKey(e => e.DeviceID);
  171.  
  172. entity.Property(e => e.CALs).HasDefaultValue(0);
  173.  
  174. entity.Property(e => e.DeviceName)
  175. .IsRequired()
  176. .HasMaxLength(50)
  177. .HasColumnType("varchar");
  178.  
  179. entity.Property(e => e.UnlockedFrom).HasColumnType("date");
  180.  
  181. entity.Property(e => e.UnlockedTo).HasColumnType("date");
  182.  
  183. entity.Property(e => e.UserId)
  184. .IsRequired()
  185. .HasMaxLength(450);
  186.  
  187. entity.HasOne(d => d.User).WithMany(p => p.Devices).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  188. });
  189.  
  190. modelBuilder.Entity<Downloads>(entity =>
  191. {
  192. entity.HasKey(e => e.DownloadId);
  193.  
  194. entity.Property(e => e.DownloadDate).HasColumnType("date");
  195.  
  196. entity.Property(e => e.DownloadVersion)
  197. .IsRequired()
  198. .HasMaxLength(50)
  199. .HasColumnType("varchar");
  200.  
  201. entity.Property(e => e.UserId)
  202. .IsRequired()
  203. .HasMaxLength(450);
  204.  
  205. entity.HasOne(d => d.User).WithMany(p => p.Downloads).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  206. });
  207.  
  208. modelBuilder.Entity<Invoices>(entity =>
  209. {
  210. entity.HasKey(e => e.InvoiceNr);
  211.  
  212. entity.Property(e => e.AddressLabel)
  213. .IsRequired()
  214. .HasMaxLength(255)
  215. .HasColumnType("varchar");
  216.  
  217. entity.Property(e => e.InvoiceDate).HasColumnType("date");
  218.  
  219. entity.Property(e => e.InvoiceDescription)
  220. .IsRequired()
  221. .HasMaxLength(255)
  222. .HasColumnType("varchar");
  223.  
  224. entity.Property(e => e.InvoiceNet).HasColumnType("money");
  225.  
  226. entity.Property(e => e.InvoiceTax).HasColumnType("money");
  227.  
  228. entity.Property(e => e.InvoiceTotal).HasColumnType("money");
  229.  
  230. entity.Property(e => e.UserId)
  231. .IsRequired()
  232. .HasMaxLength(450);
  233.  
  234. entity.HasOne(d => d.User).WithMany(p => p.Invoices).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  235. });
  236.  
  237. modelBuilder.Entity<Notes>(entity =>
  238. {
  239. entity.HasKey(e => e.NoteId);
  240.  
  241. entity.Property(e => e.NoteDate).HasColumnType("date");
  242.  
  243. entity.Property(e => e.NoteSubject)
  244. .IsRequired()
  245. .HasMaxLength(50)
  246. .HasColumnType("varchar");
  247.  
  248. entity.Property(e => e.NoteText)
  249. .IsRequired()
  250. .HasColumnType("varchar");
  251.  
  252. entity.Property(e => e.UserId)
  253. .IsRequired()
  254. .HasMaxLength(450);
  255.  
  256. entity.HasOne(d => d.User).WithMany(p => p.Notes).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  257. });
  258.  
  259. modelBuilder.Entity<ReferralSources>(entity =>
  260. {
  261. entity.HasKey(e => e.ReferralSourceId);
  262.  
  263. entity.Property(e => e.ReferralSourceName)
  264. .IsRequired()
  265. .HasMaxLength(50)
  266. .HasColumnType("varchar");
  267. });
  268.  
  269. modelBuilder.Entity<Referrals>(entity =>
  270. {
  271. entity.HasKey(e => e.ReferralId);
  272.  
  273. entity.Property(e => e.ReferralDate).HasColumnType("date");
  274.  
  275. entity.Property(e => e.UserId)
  276. .IsRequired()
  277. .HasMaxLength(450);
  278.  
  279. entity.HasOne(d => d.ReferralSource).WithMany(p => p.Referrals).HasForeignKey(d => d.ReferralSourceID).OnDelete(DeleteBehavior.Restrict);
  280.  
  281. entity.HasOne(d => d.User).WithMany(p => p.Referrals).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  282. });
  283.  
  284. modelBuilder.Entity<Subscriptions>(entity =>
  285. {
  286. entity.HasKey(e => e.SubscriptionId);
  287.  
  288. entity.Property(e => e.SubscriberId)
  289. .IsRequired()
  290. .HasMaxLength(450);
  291.  
  292. entity.Property(e => e.SubscriptionExpires).HasColumnType("date");
  293. entity.Property(e => e.TotalCALs).HasDefaultValue(0);
  294.  
  295. });
  296. }
  297.  
  298. public virtual DbSet<AspNetRoleClaims> AspNetRoleClaims { get; set; }
  299. public virtual DbSet<AspNetRoles> AspNetRoles { get; set; }
  300. public virtual DbSet<AspNetUserClaims> AspNetUserClaims { get; set; }
  301. public virtual DbSet<AspNetUserLogins> AspNetUserLogins { get; set; }
  302. public virtual DbSet<AspNetUserRoles> AspNetUserRoles { get; set; }
  303. public virtual DbSet<ApplicationUser> ApplicationUser { get; set; }
  304. public virtual DbSet<Countries> Countries { get; set; }
  305. public virtual DbSet<Devices> Devices { get; set; }
  306. public virtual DbSet<Downloads> Downloads { get; set; }
  307. public virtual DbSet<Invoices> Invoices { get; set; }
  308. public virtual DbSet<Notes> Notes { get; set; }
  309. public virtual DbSet<ReferralSources> ReferralSources { get; set; }
  310. public virtual DbSet<Referrals> Referrals { get; set; }
  311. public virtual DbSet<Subscriptions> Subscriptions { get; set; }
  312. }
  313.  
  314. var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false);
  315.  
  316. Cannot use table 'AspNetUsers' in schema '' for entity 'AspNetUsers' since it is being used for another entity.
  317.  
  318. dnx ef migrations add initial
  319.  
  320. public partial class CustomersContext : IdentityDbContext<ApplicationUser>
  321. {
  322. protected override void OnConfiguring(DbContextOptionsBuilder options)
  323. {
  324. options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Customers;Trusted_Connection=True;MultipleActiveResultSets=true");
  325. }
  326.  
  327. protected override void OnModelCreating(ModelBuilder modelBuilder)
  328. {
  329. base.OnModelCreating(modelBuilder);// we have to do this because we are inheriting from IdentityDbContext<ApplicationUser> not DbContext
  330.  
  331. // override the users tables with your properties
  332. modelBuilder.Entity<ApplicationUser>(entity =>
  333. {
  334. entity.HasIndex(e => e.BusinessName).HasName("BusinessNameIndex");
  335.  
  336. entity.HasIndex(e => e.NormalizedEmail).HasName("EmailIndex");
  337.  
  338. entity.HasIndex(e => e.NormalizedUserName).HasName("UserNameIndex");
  339.  
  340. entity.Property(e => e.Id).HasMaxLength(450);
  341.  
  342. entity.Property(e => e.AddressLabel)
  343. .HasMaxLength(255)
  344. .HasColumnType("varchar");
  345.  
  346. entity.Property(e => e.BusinessName)
  347. .HasMaxLength(255)
  348. .HasColumnType("varchar");
  349.  
  350. entity.Property(e => e.ContactName)
  351. .HasMaxLength(255)
  352. .HasColumnType("varchar");
  353.  
  354. entity.Property(e => e.CountryCode)
  355. .IsRequired()
  356. .HasMaxLength(2)
  357. .HasColumnType("varchar")
  358. .HasDefaultValue("00");
  359.  
  360. entity.Property(e => e.FollowUp).HasColumnType("date");
  361.  
  362. entity.Property(e => e.MailingList).HasDefaultValue(true);
  363.  
  364. entity.HasOne(d => d.Country).WithMany(p => p.Users).HasForeignKey(d => d.CountryCode).OnDelete(DeleteBehavior.Restrict);
  365.  
  366. entity.HasOne(d => d.Subscription).WithMany(p => p.Users).HasForeignKey(d => d.SubscriptionId).OnDelete(DeleteBehavior.Restrict);
  367. });
  368.  
  369. modelBuilder.Entity<Countries>(entity =>
  370. {
  371. entity.HasKey(e => e.CountryCode);
  372.  
  373. entity.Property(e => e.CountryCode)
  374. .HasMaxLength(2)
  375. .HasColumnType("varchar");
  376.  
  377. entity.Property(e => e.CalCost).HasColumnType("decimal");
  378.  
  379. entity.Property(e => e.CountryName)
  380. .IsRequired()
  381. .HasMaxLength(50)
  382. .HasColumnType("varchar");
  383.  
  384. entity.Property(e => e.CultureCode)
  385. .IsRequired()
  386. .HasMaxLength(8)
  387. .HasColumnType("varchar");
  388.  
  389. entity.Property(e => e.CurrencyCode)
  390. .IsRequired()
  391. .HasMaxLength(3)
  392. .HasColumnType("varchar");
  393.  
  394. entity.Property(e => e.InvoiceFooter)
  395. .HasMaxLength(50)
  396. .HasColumnType("varchar");
  397.  
  398. entity.Property(e => e.InvoiceName)
  399. .IsRequired()
  400. .HasMaxLength(50)
  401. .HasColumnType("varchar");
  402.  
  403. entity.Property(e => e.TaxName)
  404. .HasMaxLength(3)
  405. .HasColumnType("varchar");
  406.  
  407. entity.Property(e => e.TaxRate).HasColumnType("decimal");
  408. });
  409.  
  410. modelBuilder.Entity<Devices>(entity =>
  411. {
  412. entity.HasKey(e => e.DeviceID);
  413.  
  414. entity.Property(e => e.CALs).HasDefaultValue(0);
  415.  
  416. entity.Property(e => e.DeviceName)
  417. .IsRequired()
  418. .HasMaxLength(50)
  419. .HasColumnType("varchar");
  420.  
  421. entity.Property(e => e.UnlockedFrom).HasColumnType("date");
  422.  
  423. entity.Property(e => e.UnlockedTo).HasColumnType("date");
  424.  
  425. entity.Property(e => e.UserId)
  426. .IsRequired()
  427. .HasMaxLength(450);
  428.  
  429. entity.HasOne(d => d.User).WithMany(p => p.Devices).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  430. });
  431.  
  432. modelBuilder.Entity<Downloads>(entity =>
  433. {
  434. entity.HasKey(e => e.DownloadId);
  435.  
  436. entity.Property(e => e.DownloadDate).HasColumnType("date");
  437.  
  438. entity.Property(e => e.DownloadVersion)
  439. .IsRequired()
  440. .HasMaxLength(50)
  441. .HasColumnType("varchar");
  442.  
  443. entity.Property(e => e.UserId)
  444. .IsRequired()
  445. .HasMaxLength(450);
  446.  
  447. entity.HasOne(d => d.User).WithMany(p => p.Downloads).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  448. });
  449.  
  450. modelBuilder.Entity<Invoices>(entity =>
  451. {
  452. entity.HasKey(e => e.InvoiceNr);
  453.  
  454. entity.Property(e => e.AddressLabel)
  455. .IsRequired()
  456. .HasMaxLength(255)
  457. .HasColumnType("varchar");
  458.  
  459. entity.Property(e => e.InvoiceDate).HasColumnType("date");
  460.  
  461. entity.Property(e => e.InvoiceDescription)
  462. .IsRequired()
  463. .HasMaxLength(255)
  464. .HasColumnType("varchar");
  465.  
  466. entity.Property(e => e.InvoiceNet).HasColumnType("money");
  467.  
  468. entity.Property(e => e.InvoiceTax).HasColumnType("money");
  469.  
  470. entity.Property(e => e.InvoiceTotal).HasColumnType("money");
  471.  
  472. entity.Property(e => e.UserId)
  473. .IsRequired()
  474. .HasMaxLength(450);
  475.  
  476. entity.HasOne(d => d.User).WithMany(p => p.Invoices).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  477. });
  478.  
  479. modelBuilder.Entity<Notes>(entity =>
  480. {
  481. entity.HasKey(e => e.NoteId);
  482.  
  483. entity.Property(e => e.NoteDate).HasColumnType("date");
  484.  
  485. entity.Property(e => e.NoteSubject)
  486. .IsRequired()
  487. .HasMaxLength(50)
  488. .HasColumnType("varchar");
  489.  
  490. entity.Property(e => e.NoteText)
  491. .IsRequired()
  492. .HasColumnType("varchar");
  493.  
  494. entity.Property(e => e.UserId)
  495. .IsRequired()
  496. .HasMaxLength(450);
  497.  
  498. entity.HasOne(d => d.User).WithMany(p => p.Notes).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  499. });
  500.  
  501. modelBuilder.Entity<ReferralSources>(entity =>
  502. {
  503. entity.HasKey(e => e.ReferralSourceId);
  504.  
  505. entity.Property(e => e.ReferralSourceName)
  506. .IsRequired()
  507. .HasMaxLength(50)
  508. .HasColumnType("varchar");
  509. });
  510.  
  511. modelBuilder.Entity<Referrals>(entity =>
  512. {
  513. entity.HasKey(e => e.ReferralId);
  514.  
  515. entity.Property(e => e.ReferralDate).HasColumnType("date");
  516.  
  517. entity.Property(e => e.UserId)
  518. .IsRequired()
  519. .HasMaxLength(450);
  520.  
  521. entity.HasOne(d => d.ReferralSource).WithMany(p => p.Referrals).HasForeignKey(d => d.ReferralSourceID).OnDelete(DeleteBehavior.Restrict);
  522.  
  523. entity.HasOne(d => d.User).WithMany(p => p.Referrals).HasForeignKey(d => d.UserId).OnDelete(DeleteBehavior.Restrict);
  524. });
  525.  
  526. modelBuilder.Entity<Subscriptions>(entity =>
  527. {
  528. entity.HasKey(e => e.SubscriptionId);
  529.  
  530. entity.Property(e => e.SubscriberId)
  531. .IsRequired()
  532. .HasMaxLength(450);
  533.  
  534. entity.Property(e => e.SubscriptionExpires).HasColumnType("date");
  535. entity.Property(e => e.TotalCALs).HasDefaultValue(0);
  536.  
  537. });
  538. }
  539.  
  540. public virtual DbSet<Countries> Countries { get; set; }
  541. public virtual DbSet<Devices> Devices { get; set; }
  542. public virtual DbSet<Downloads> Downloads { get; set; }
  543. public virtual DbSet<Invoices> Invoices { get; set; }
  544. public virtual DbSet<Notes> Notes { get; set; }
  545. public virtual DbSet<ReferralSources> ReferralSources { get; set; }
  546. public virtual DbSet<Referrals> Referrals { get; set; }
  547. public virtual DbSet<Subscriptions> Subscriptions { get; set; }
  548. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement