Advertisement
Rhazai

Untitled

Oct 21st, 2019
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.18 KB | None | 0 0
  1. using System;
  2. using Microsoft.EntityFrameworkCore;
  3. using MbmStore.Models;
  4. using System.Collections.Generic;
  5.  
  6. namespace MbmStore.Data
  7. {
  8. public class MbmStoreContext : DbContext
  9. {
  10. public MbmStoreContext(DbContextOptions<MbmStoreContext> options)
  11. : base(options)
  12. {
  13. }
  14. public DbSet<Customer> Customers { get; set; }
  15. public DbSet<Phone> Phones { get; set; }
  16. public DbSet<Invoice> Invoices { get; set; }
  17. public DbSet<OrderItem> OrderItems { get; set; }
  18. public DbSet<Product> Products { get; set; }
  19.  
  20. public DbSet<Book> Books { get; set; }
  21. public DbSet<Movie> Movies { get; set; }
  22. public DbSet<MusicCD> MusicCDs { get; set; }
  23.  
  24. protected override void OnModelCreating(ModelBuilder modelBuilder)
  25. {
  26. modelBuilder.Entity<Customer>().ToTable("Customer");
  27. modelBuilder.Entity<Phone>().ToTable("Phone");
  28. modelBuilder.Entity<Invoice>().ToTable("Invoice");
  29. modelBuilder.Entity<OrderItem>().ToTable("OrderItem");
  30. modelBuilder.Entity<Product>().ToTable("Product");
  31. modelBuilder.Entity<Book>().ToTable("Book");
  32. modelBuilder.Entity<Movie>().ToTable("Movie");
  33. modelBuilder.Entity<MusicCD>().ToTable("MusicCD");
  34. modelBuilder.Entity<Book>().HasData(
  35. new Book
  36. {
  37. ProductId = 1,
  38. Title = "A Hard Day's Write: The Stories Behind Every Beatles Song ",
  39. Author = "Steve Turner",
  40. Price = 150.00M,
  41. Publisher = "It Books",
  42. Published = 2005,
  43. ISBN = "978-0060844097", ImageUrl = "A_Hard_Days_Write.jpg", Category = "Book" },
  44.  
  45. new Book
  46. {
  47. ProductId = 2,
  48. Title = "With a Little Help from My Friends: The Making of Sgt.Pepper", Author = "Georg Martin", Price = 180.00M, Publisher = "Little Brown & Co", Published = 1995,
  49. ISBN = "0316547832",
  50. ImageUrl = "The Making of Sgt. Pepper.jpg",
  51. Category = "Book"
  52. }
  53. );
  54.  
  55. modelBuilder.Entity<MusicCD>().HasData(
  56. new MusicCD
  57. {
  58. ProductId = 3,
  59. Title = "Abbey Road (Remastered)",
  60. Artist = "Beatles",
  61. Price = 128.00M,
  62. Released = 2009,
  63. Label = "EMI",
  64. ImageUrl = "abbey_road.jpg",
  65. Category = "Music"
  66. },
  67. new MusicCD
  68. {
  69. ProductId = 4,
  70. Title = "Revolver (Remastered)",
  71. Artist = "The Beatles",
  72. Price = 128.00M,
  73. Released = 2009,
  74. Label = "EMI",
  75. ImageUrl = "revolver.jpg",
  76. Category = "Music"
  77. }
  78. );
  79. modelBuilder.Entity<Movie>().HasData(
  80. new Movie
  81. {
  82. ProductId = 5,
  83. Title = "Jungle Book",
  84. Price = 160.50M,
  85. ImageUrl = "junglebook.jpg",
  86. Director = "Jon Favreau",
  87. Category = "Movie"
  88. },
  89. new Movie
  90. {
  91. ProductId = 6,
  92. Title = "Gladiator",
  93. Price = 49.95M,
  94. ImageUrl = "gladiator.jpg",
  95. Director
  96. = "Ridley Scott",
  97. Category = "Movie"
  98. },
  99. new Movie { ProductId = 7, Title = "Forrest Gump", Price = 160.50M, ImageUrl = "forrestgump.jpg", Director = "Robert Zemeckis", Category = "Movie" }
  100. );
  101. modelBuilder.Entity<Track>().HasData(
  102. new Track
  103. {
  104. TrackId = 1,
  105. Title = "Come Together",
  106. Length = new TimeSpan(0, 4, 20),
  107. Composer =
  108. "Lennon, McCartney",
  109. ProductId = 3
  110. },
  111. new Track
  112. {
  113. TrackId = 2,
  114. Title = "Something",
  115. Length = new TimeSpan(0, 3, 03),
  116. Composer =
  117. "Harrison",
  118. ProductId = 3
  119. },
  120. new Track
  121. {
  122. TrackId = 3,
  123. Title = "Maxwell's Silver Hammer",
  124. Length = new TimeSpan(0, 3, 29),
  125. Composer = "Lennon, McCartney",
  126. ProductId = 3
  127. },
  128. new Track
  129. {
  130. TrackId = 4,
  131. Title = "Oh! Darling",
  132. Length = new TimeSpan(0, 3, 26),
  133. Composer =
  134. "Lennon, McCartney",
  135. ProductId = 3
  136. },
  137. new Track
  138. {
  139. TrackId = 5,
  140. Title = "Octopus's Garden",
  141. Length = new TimeSpan(0, 2, 51),
  142. Composer
  143. = "Starkey",
  144. ProductId = 3
  145. },
  146. new Track
  147. {
  148. TrackId = 6,
  149. Title = "I Want You (She's So Heavy)",
  150. Length = new TimeSpan(0, 7, 47),
  151. Composer = "Lennon, McCartney",
  152. ProductId = 3
  153. },
  154. new Track
  155. {
  156. TrackId = 7,
  157. Title = "Here Comes The Sun",
  158. Length = new TimeSpan(0, 3, 05),
  159. Composer = "Harrison",
  160. ProductId = 3
  161. },
  162. new Track
  163. {
  164. TrackId = 8,
  165. Title = "Because",
  166. Length = new TimeSpan(0, 2, 45),
  167. Composer =
  168. "Lennon, McCartney",
  169. ProductId = 3
  170. },
  171. new Track
  172. {
  173. TrackId = 9,
  174. Title = "You Never Give Me Your Money",
  175. Length = new TimeSpan(0, 4,
  176. 02),
  177. Composer = "Lennon, McCartney",
  178. ProductId = 3
  179. },
  180. new Track
  181. {
  182. TrackId = 10,
  183. Title = "Sun King",
  184. Length = new TimeSpan(0, 2, 26),
  185. Composer =
  186. "Lennon, McCartney",
  187. ProductId = 3
  188. },
  189. new Track
  190. {
  191. TrackId = 11,
  192. Title = "Mean Mr. Mustard",
  193. Length = new TimeSpan(0, 1, 6),
  194. Composer
  195. = "Lennon, McCartney",
  196. ProductId = 3
  197. },
  198. new Track
  199. {
  200. TrackId = 12,
  201. Title = "Polythene Pam",
  202. Length = new TimeSpan(0, 1, 12),
  203. Composer =
  204. "Lennon, McCartney",
  205. ProductId = 3
  206. },
  207. new Track
  208. {
  209. TrackId = 13,
  210. Title = "She Came In Through The Bathroom Window",
  211. Length = new
  212. TimeSpan(0, 1, 57),
  213. Composer = "Lennon, McCartney",
  214. ProductId = 3
  215. },
  216. new Track
  217. {
  218. TrackId = 14,
  219. Title = "Golden Slumbers",
  220. Length = new TimeSpan(0, 1, 31),
  221. Composer
  222. = "Lennon, McCartney",
  223. ProductId = 3
  224. },
  225. new Track
  226. {
  227. TrackId = 15,
  228. Title = "Carry That Weight",
  229. Length = new TimeSpan(0, 1, 36),
  230. Composer = "Lennon, McCartney",
  231. ProductId = 3
  232. },
  233. new Track
  234. {
  235. TrackId = 16,
  236. Title = "The End",
  237. Length = new TimeSpan(0, 2, 19),
  238. Composer =
  239. "Lennon, McCartney",
  240. ProductId = 3
  241. },
  242. new Track
  243. {
  244. TrackId = 17,
  245. Title = "Her Majesty",
  246. Length = new TimeSpan(0, 0, 23),
  247. Composer =
  248. "Lennon, McCartney",
  249. ProductId = 3
  250. },
  251. new Track
  252. {
  253. TrackId = 18,
  254. Title = "Taxman",
  255. Length = new TimeSpan(0, 2, 28),
  256. Composer =
  257. "Harrison",
  258. ProductId = 4
  259. },
  260. new Track
  261. {
  262. TrackId = 19,
  263. Title = "Eleanor Rigby",
  264. Length = new TimeSpan(0, 2, 6),
  265. Composer =
  266. "Lennon, McCartney",
  267. ProductId = 4
  268. },
  269. new Track
  270. {
  271. TrackId = 20,
  272. Title = "I'm Only Sleeping",
  273. Length = new TimeSpan(0, 3, 0),
  274. Composer =
  275. "Lennon, McCartney",
  276. ProductId = 4
  277. },
  278. new Track
  279. {
  280. TrackId = 21,
  281. Title = "Love You To",
  282. Length = new TimeSpan(0, 2, 59),
  283. Composer =
  284. "Harrison",
  285. ProductId = 4
  286. },
  287. new Track
  288. {
  289. TrackId = 22,
  290. Title = "Here, There And Everywhere",
  291. Length = new TimeSpan(0, 2,
  292. 23),
  293. Composer = "Harrison",
  294. ProductId = 4
  295. },
  296. new Track
  297. {
  298. TrackId = 23,
  299. Title = "Yellow Submarine",
  300. Length = new TimeSpan(0, 2, 38),
  301. Composer = "Lennon, McCartney",
  302. ProductId = 4
  303. },
  304. new Track
  305. {
  306. TrackId = 24,
  307. Title = "She Said She Said",
  308. Length = new TimeSpan(0, 2, 36),
  309. Composer
  310. = "Lennon, McCartney",
  311. ProductId = 4
  312. },
  313. new Track
  314. {
  315. TrackId = 25,
  316. Title = "Good Day Sunshine",
  317. Length = new TimeSpan(0, 2, 9),
  318. Composer = "Lennon, McCartney",
  319. ProductId = 4
  320. },
  321. new Track
  322. {
  323. TrackId = 26,
  324. Title = "And Your Bird Can Sing",
  325. Length = new TimeSpan(0, 2, 0),
  326. Composer = "Lennon, McCartney",
  327. ProductId = 4
  328. },
  329. new Track
  330. {
  331. TrackId = 27,
  332. Title = "For No One",
  333. Length = new TimeSpan(0, 1, 59),
  334. Composer =
  335. "Lennon, McCartney",
  336. ProductId = 4
  337. },
  338. new Track
  339. {
  340. TrackId = 28,
  341. Title = "Doctor Robert",
  342. Length = new TimeSpan(0, 1, 14),
  343. Composer =
  344. "Lennon, McCartney",
  345. ProductId = 4
  346. },
  347. new Track
  348. {
  349. TrackId = 29,
  350. Title = "I Want To Tell You",
  351. Length = new TimeSpan(0, 2, 27),
  352. Composer = "Harrison",
  353. ProductId = 4
  354. },
  355. new Track
  356. {
  357. TrackId = 30,
  358. Title = "Got To Get You Into My Life",
  359. Length = new TimeSpan(0, 2, 29),
  360. Composer = "Lennon, McCartney",
  361. ProductId = 4
  362. },
  363. new Track
  364. {
  365. TrackId = 31,
  366. Title = "Tomorrow Newer Knows",
  367. Length = new TimeSpan(0, 3, 01),
  368. Composer = "Lennon, McCartney",
  369. ProductId = 4
  370. }
  371. );
  372. modelBuilder.Entity<Customer>().HasData(
  373. new Customer
  374. {
  375. CustomerId = 1,
  376. Firstname = "Tina",
  377. Lastname = "Petterson",
  378. Address =
  379. "Irisdahlsvej 32",
  380. Zip = "8200",
  381. City = "Århus N"
  382. },
  383. new Customer
  384. {
  385. CustomerId = 2,
  386. Firstname = "Thomas",
  387. Lastname = "Larsson",
  388. Address =
  389. "Solsikkevej 32",
  390. Zip = "8000",
  391. City = "Århus C"
  392. }
  393. );
  394. modelBuilder.Entity<Invoice>().HasData(
  395. new Invoice { InvoiceId = 1, OrderDate = new DateTime(2018, 09, 12), CustomerId = 1 },
  396. new Invoice { InvoiceId = 2, OrderDate = new DateTime(2018, 09, 18), CustomerId = 2 }
  397. );
  398. modelBuilder.Entity<OrderItem>().HasData(
  399. new OrderItem { OrderItemId = 1, ProductId = 7, Quantity = 1, InvoiceId = 1 },
  400. new OrderItem { OrderItemId = 2, ProductId = 2, Quantity = 1, InvoiceId = 1 },
  401. new OrderItem { OrderItemId = 3, ProductId = 1, Quantity = 1, InvoiceId = 2 },
  402. new OrderItem { OrderItemId = 4, ProductId = 3, Quantity = 1, InvoiceId = 2 }
  403. );
  404. }
  405. }
  406. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement