1 00:00:00,000 --> 00:00:04,896 [MUSIC] 2 00:00:04,896 --> 00:00:06,450 Welcome back. 3 00:00:06,450 --> 00:00:10,200 Another developer on our team heard that we had just finished development of 4 00:00:10,200 --> 00:00:12,180 a comic books data model. 5 00:00:12,180 --> 00:00:14,650 They are a huge fan of comic books. 6 00:00:14,650 --> 00:00:19,910 So they took a copy of our EF model and built a simple console app on top of it. 7 00:00:19,910 --> 00:00:21,140 Let's take a look at what they've built. 8 00:00:22,510 --> 00:00:25,804 Here's the project for the Comic Book Library Manager console lab. 9 00:00:29,614 --> 00:00:34,120 After starting the app, we're presented with a list of the available comic books. 10 00:00:34,120 --> 00:00:36,160 We can type a to add a comic book. 11 00:00:38,060 --> 00:00:40,030 We're prompted to select the series. 12 00:00:41,600 --> 00:00:42,886 And an issue number. 13 00:00:42,886 --> 00:00:52,330 The description, The published on date. 14 00:00:55,420 --> 00:00:59,338 The average rating. 15 00:00:59,338 --> 00:01:01,221 The artist. 16 00:01:01,221 --> 00:01:03,130 And the artists role. 17 00:01:05,390 --> 00:01:08,260 Then we're returned to the list of comic books 18 00:01:08,260 --> 00:01:11,080 which now includes the comic book that we just added. 19 00:01:13,240 --> 00:01:16,510 We can type a line number to view the detail for that comic book. 20 00:01:18,760 --> 00:01:21,910 From here, we can type u to update the comic book. 21 00:01:23,490 --> 00:01:27,720 We're then presented with a list of the properties that we can change. 22 00:01:27,720 --> 00:01:30,725 I'll type 2 to change the issue number value. 23 00:01:33,451 --> 00:01:37,690 Once we've made all the changes that we want to make, enter S to save. 24 00:01:39,820 --> 00:01:43,410 Now we're viewing the detail for our selected comic book again. 25 00:01:43,410 --> 00:01:45,920 Notice that the issue number has been changed to five. 26 00:01:48,620 --> 00:01:53,950 We can delete the comic book by entering D and then Y to confirm the deletion. 27 00:01:56,450 --> 00:01:59,230 And here's the list of the comic books again 28 00:01:59,230 --> 00:02:01,450 without the comic book that we just deleted. 29 00:02:02,900 --> 00:02:04,560 Let's review the architecture of the app. 30 00:02:05,790 --> 00:02:09,630 When they built their app, they put all the code that interacted with the EF 31 00:02:09,630 --> 00:02:14,350 context class into its own class named Repository. 32 00:02:14,350 --> 00:02:18,420 Whenever they need to retrieve entities from the database or add, update, or 33 00:02:18,420 --> 00:02:19,600 delete an entity. 34 00:02:19,600 --> 00:02:22,220 They call a method on the repository class 35 00:02:22,220 --> 00:02:24,470 instead of using the contents class directly. 36 00:02:25,500 --> 00:02:28,720 With this design the only part of their app that has 37 00:02:28,720 --> 00:02:33,240 any knowledge of the context class is the repository class. 38 00:02:33,240 --> 00:02:37,810 Using this approach makes it very simple for the rest of the app to retrieve and 39 00:02:37,810 --> 00:02:39,370 persist data. 40 00:02:39,370 --> 00:02:44,175 As we've seen in previous treehouse courses by organizing our data access 41 00:02:44,175 --> 00:02:48,839 code in this way, we're implementing the repository design pattern. 42 00:02:48,839 --> 00:02:52,543 All of the application code lives in the app layer, 43 00:02:52,543 --> 00:02:58,421 the repository class along with the context and database initializer classes. 44 00:02:58,421 --> 00:03:01,830 Livein the data access layer or DAL. 45 00:03:02,870 --> 00:03:07,560 The entity classes are shared between the app and data access layers. 46 00:03:08,660 --> 00:03:13,020 Separating our code into layers, gives us greater flexibility. 47 00:03:13,020 --> 00:03:14,090 For example, 48 00:03:14,090 --> 00:03:19,780 we could build additional app layer implementations like a web or desktop app. 49 00:03:19,780 --> 00:03:21,720 Or maybe even a mobile app. 50 00:03:21,720 --> 00:03:25,520 Without having to rewrite or change the data access layer. 51 00:03:26,650 --> 00:03:30,330 In this section we'll learn how to perform CRUD operations, 52 00:03:30,330 --> 00:03:35,690 specifically create, update and delete with EF context class. 53 00:03:35,690 --> 00:03:40,480 As we do that we'll be implementing the various methods in the repository class 54 00:03:40,480 --> 00:03:43,560 in the comic book library managers data access layer. 55 00:03:44,560 --> 00:03:46,660 I'd encourage you to follow along. 56 00:03:46,660 --> 00:03:50,620 Writing code is an important part of the learning process. 57 00:03:50,620 --> 00:03:54,360 You'll gain a deeper understanding of the material that will cover, and 58 00:03:54,360 --> 00:03:56,290 you'll improve your retention. 59 00:03:56,290 --> 00:03:59,539 See the teacher's notes for a link to download the Visual Studio project. 60 00:04:00,640 --> 00:04:05,660 Let's start by seeing how we can use the EF context to create new entities. 61 00:04:05,660 --> 00:04:06,580 See you after the break.