Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. [Table("Address")]
  2. public class Address
  3. {
  4. [Key]
  5. public long AddressId { get; set; }
  6. public string Address1 { get; set; }
  7. public string Address2 { get; set; }
  8. public string Address3 { get; set; }
  9. public string Address4 { get; set; }
  10. public string Address5 { get; set; }
  11. public string Town { get; set; }
  12. public string County { get; set; }
  13. public string Country { get; set; }
  14. public string PostCode { get; set; }
  15. public virtual Company Company { get; set; }
  16. public DateTime? RemovedDate { get; set; }
  17. public long? RemovedBy { get; set; }
  18. }
  19.  
  20. [Table("Company")]
  21. public class Company
  22. {
  23. [Key ]
  24. public long CompanyId { get; set; }
  25. public string Name { get; set; }
  26. public string WebsiteUrl { get; set; }
  27. public virtual Address Address { get; set; }
  28. public User LeadUser { get; set; }
  29. public DateTime ActiveSince { get; set; }
  30. public DateTime? ActiveTill { get; set; }
  31. public string VatRegistration { get; set; }
  32. public string LicenseKey { get; set; }
  33. public LicenseStatus LicenseStatus { get; set; }
  34. public bool CanAgreementBeExtended { get; set; }
  35. public string BillingEmail { get; set; }
  36. public string PhoneNumber { get; set; }
  37. public string MobileNumber { get; set; }
  38. public DateTime DateCreated { get; set; }
  39. public DateTime DateUpdated { get; set; }
  40. public virtual ICollection<User> Users { get; set; }
  41. public virtual ICollection<LicenseHistory> LicenseHistories { get; set; }
  42. }
  43.  
  44. //Seeded data inserted as follows
  45. var testCompany = new Company
  46. {
  47. ActiveSince = DateTime.UtcNow,
  48. Name = "Test Company",
  49. LeadUser = adminUser,
  50. DateCreated = DateTime.UtcNow,
  51. DateUpdated = DateTime.UtcNow,
  52. BillingEmail = "admin@test.co.uk",
  53. CanAgreementBeExtended = true,
  54. LicenseStatus = LicenseStatus.PendingAgreement,
  55. MobileNumber = "1234567890",
  56. PhoneNumber = "1234567890",
  57. VatRegistration = "1234567890"
  58. };
  59.  
  60. context.Companies.AddOrUpdate(u => u.Name, testCompany);
  61.  
  62. var testAddress = new Address
  63. {
  64. Address1 = "Test Ltd",
  65. Address2 = "1 Test Gardens",
  66. Address3 = "Test Heath",
  67. Address4 = string.Empty,
  68. Address5 = string.Empty,
  69. County = "Test",
  70. Town = "Test",
  71. Country = "United Kingdom",
  72. PostCode = "TE5 T11",
  73. Company = testCompany
  74. };
  75.  
  76. context.Addresses.AddOrUpdate(u => new { u.AddressId }, testAddress);
  77.  
  78. testCompany.Address = testAddress;
  79.  
  80. context.Companies.AddOrUpdate(u => u.Name, testCompany);
  81.  
  82. //Fluent API set up as follows in the OnModelCreating
  83. modelBuilder.Entity<Address>()
  84. .HasRequired(ad => ad.Company)
  85. .WithOptional(s => s.Address);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement