1 00:00:00,600 --> 00:00:01,320 ‫Welcome back. 2 00:00:01,350 --> 00:00:04,500 ‫In this video, we are going to check out all the lecture stuff. 3 00:00:04,500 --> 00:00:06,390 ‫So, first of all, we're going to add lectures. 4 00:00:06,390 --> 00:00:12,840 ‫So insert them into our tables and then we're going to create this associative table. 5 00:00:12,840 --> 00:00:17,730 ‫Well, we're going to add information to this sort of table called the Student Lecture. 6 00:00:17,730 --> 00:00:26,460 ‫So I'm going to create a new method, public void, insert lectures, and you might know how to do that. 7 00:00:26,460 --> 00:00:33,240 ‫You might remember how to add lectures or add something to a table so you can try yourself. 8 00:00:33,360 --> 00:00:35,730 ‫You can pause the video and try to add lectures yourself. 9 00:00:35,730 --> 00:00:37,620 ‫You can even think of your own lectures. 10 00:00:38,010 --> 00:00:38,310 ‫All right. 11 00:00:38,310 --> 00:00:40,290 ‫I'm going to just use the quick and dirty version. 12 00:00:40,290 --> 00:00:45,840 ‫So data, context, dot lectures and now it's complaining. 13 00:00:45,840 --> 00:00:47,370 ‫Oh, man, there are no lectures. 14 00:00:47,370 --> 00:00:48,780 ‫What the hell do you want from me? 15 00:00:48,780 --> 00:00:49,200 ‫I don't know. 16 00:00:49,200 --> 00:00:51,300 ‫What is lecture or lectures? 17 00:00:51,300 --> 00:00:53,040 ‫Method or class should be. 18 00:00:53,040 --> 00:00:58,950 ‫So what I'm going to do is I'm going to add lecture like that in here. 19 00:00:59,190 --> 00:01:02,370 ‫So the were now this lecture table. 20 00:01:03,970 --> 00:01:05,160 ‫Can go ahead. 21 00:01:05,170 --> 00:01:15,760 ‫So let's go into the CSS file and here lecture now should come up within a couple of seconds and then 22 00:01:15,760 --> 00:01:27,190 ‫we are like, cheers, there it is, insert on submit and I'm going to add a new lecture with the name 23 00:01:27,400 --> 00:01:29,920 ‫of math. 24 00:01:29,920 --> 00:01:34,570 ‫So there is a lecture called math and you might have thought of your own lectures. 25 00:01:34,570 --> 00:01:40,450 ‫So I'm going to add another lecture in here, and the next one will be something like history. 26 00:01:43,120 --> 00:01:47,320 ‫All right, now let's add those to the table. 27 00:01:47,380 --> 00:01:50,950 ‫So data, context, don't submit changes. 28 00:01:52,180 --> 00:02:01,810 ‫And finally update our main data grid and items source because I want to see the different lectures 29 00:02:01,810 --> 00:02:02,350 ‫that I have. 30 00:02:02,350 --> 00:02:05,170 ‫So data context, start lectures. 31 00:02:06,550 --> 00:02:07,060 ‫All right. 32 00:02:07,060 --> 00:02:11,590 ‫So now let's call this method instead of our insert student method. 33 00:02:12,250 --> 00:02:15,970 ‫So insert lectures like that. 34 00:02:18,340 --> 00:02:19,000 ‫All right. 35 00:02:19,180 --> 00:02:26,050 ‫So let's run the code, and we should see the two lectures that we have set and that we are ID one math 36 00:02:26,050 --> 00:02:27,760 ‫and ID two history. 37 00:02:28,420 --> 00:02:34,630 ‫All right, now we need to have this associative table because we have created this associative table, 38 00:02:34,630 --> 00:02:38,380 ‫student lecture, and it combines students with lectures. 39 00:02:38,380 --> 00:02:42,970 ‫So the idea of a student and the idea of a lecture are connected to each other. 40 00:02:42,970 --> 00:02:45,490 ‫So we know which student has which lecture. 41 00:02:45,490 --> 00:02:49,210 ‫So let's say not every student has math and every student has history. 42 00:02:49,210 --> 00:02:56,920 ‫So in order to do that, we're going to create another method with this associative table public void, 43 00:02:56,920 --> 00:03:05,380 ‫insert student lecture associations like that. 44 00:03:05,890 --> 00:03:12,250 ‫So in here what I want to do, I want to add multiple students and multiple lectures. 45 00:03:12,250 --> 00:03:18,730 ‫So in fact, all of my four students and all of my two lectures and I want to use them as objects in 46 00:03:18,730 --> 00:03:22,900 ‫order to create those student lecture connections. 47 00:03:22,900 --> 00:03:29,080 ‫So please go ahead and try to create all the student objects and all the lecture objects that we have 48 00:03:29,080 --> 00:03:30,160 ‫in our table. 49 00:03:32,410 --> 00:03:33,420 ‫I hope you tried it. 50 00:03:33,430 --> 00:03:41,110 ‫So first of all, I want to have a student, which I'm going to call Carla and she is a data context 51 00:03:41,110 --> 00:03:45,040 ‫dot students dot first. 52 00:03:45,460 --> 00:03:50,680 ‫So I'm going to get the first student and I'm going to use the same approach that we have used with 53 00:03:50,680 --> 00:03:54,220 ‫the universities so equals here. 54 00:03:54,220 --> 00:03:56,410 ‫It's Carla like that. 55 00:03:57,070 --> 00:04:02,530 ‫And this approach here that we have is exactly the same that we used here with the universities. 56 00:04:02,530 --> 00:04:07,390 ‫So I'm getting the first student in my students data context. 57 00:04:08,320 --> 00:04:16,840 ‫So here, which has the name or what name equals to Karla and I do the same thing with my other students. 58 00:04:16,840 --> 00:04:18,580 ‫So the other one was Tony. 59 00:04:18,700 --> 00:04:21,700 ‫And there the name was Toni. 60 00:04:21,790 --> 00:04:29,050 ‫Then we had Layla, which I accidentally called Layla, so I'm going to call her Layla here as well. 61 00:04:29,050 --> 00:04:32,290 ‫And then we had James, which I accidentally called James. 62 00:04:32,710 --> 00:04:36,220 ‫So I'm going to search for James here as well. 63 00:04:36,400 --> 00:04:38,860 ‫And that's the students and now the lecture. 64 00:04:38,860 --> 00:04:43,930 ‫So if you didn't manage to get the lectures as well or the students either, then please try to do that 65 00:04:43,930 --> 00:04:47,860 ‫with the lectures now, because now you see how it's done with the students. 66 00:04:49,240 --> 00:04:49,680 ‫Okay. 67 00:04:49,840 --> 00:04:58,330 ‫So lecture and it was math, which is data context that lectures thought first. 68 00:04:58,330 --> 00:05:11,620 ‫So we get the first lecture and here I'm going to call it LC and it will be the LC name equals and that 69 00:05:11,620 --> 00:05:12,370 ‫was math. 70 00:05:13,240 --> 00:05:14,860 ‫So that's our lecture math. 71 00:05:14,860 --> 00:05:18,100 ‫And now let's create the second lecture, which was history. 72 00:05:19,090 --> 00:05:22,720 ‫And this one will be history like that. 73 00:05:23,320 --> 00:05:27,490 ‫And now we can create student lectures. 74 00:05:27,490 --> 00:05:29,590 ‫So that's pretty decent. 75 00:05:29,740 --> 00:05:32,350 ‫We can go the data context and here. 76 00:05:32,350 --> 00:05:35,650 ‫Student Oh, it doesn't show me student lectures. 77 00:05:35,650 --> 00:05:36,340 ‫Why is that? 78 00:05:36,340 --> 00:05:40,810 ‫Well, you hopefully know it's because we don't have it here. 79 00:05:40,810 --> 00:05:43,630 ‫So let's create a student lecture and put it in here. 80 00:05:44,380 --> 00:05:51,910 ‫And as you can see, student lecture is connected with student and lecture, so let me drag them correctly. 81 00:05:51,910 --> 00:05:59,710 ‫So you see, the student is connected to university, so a student is in one university, but a university 82 00:05:59,710 --> 00:06:01,120 ‫has multiple students. 83 00:06:01,330 --> 00:06:05,740 ‫Then a student's a student has student lectures. 84 00:06:05,740 --> 00:06:11,380 ‫Well, it has lectures, but they are both connected to the student lecture table. 85 00:06:11,380 --> 00:06:16,570 ‫So lecture and student are connected in student lecture, as you can see, is because of the student 86 00:06:16,570 --> 00:06:18,130 ‫ID and a lecture ID. 87 00:06:18,220 --> 00:06:20,890 ‫That's why they are connected here. 88 00:06:21,700 --> 00:06:27,340 ‫So now what we can do is create a student lecture. 89 00:06:27,340 --> 00:06:36,640 ‫So I'm going to use data context student or yeah, it's actually student lectures like that and insert 90 00:06:36,640 --> 00:06:38,020 ‫on submit. 91 00:06:39,190 --> 00:06:40,600 ‫And what do I want to submit. 92 00:06:40,600 --> 00:06:49,780 ‫Well, a new student lecture entity and that will be with the student, let's say this one is with Carla 93 00:06:50,200 --> 00:06:53,440 ‫and she has a lecture called math. 94 00:06:54,790 --> 00:06:59,380 ‫So now we're not saying called math, but we're actually saying the math object. 95 00:06:59,680 --> 00:07:07,090 ‫So the object, Carla, and the object math are connected and object Carla is of type student and object 96 00:07:07,090 --> 00:07:09,130 ‫lecture or math as of type lecture. 97 00:07:09,130 --> 00:07:11,590 ‫So now we're connecting them in this one line. 98 00:07:11,590 --> 00:07:15,190 ‫Now let's do it again with another student and another lecture. 99 00:07:15,190 --> 00:07:18,070 ‫So let's say Tony also has math. 100 00:07:18,280 --> 00:07:23,740 ‫So now we have those two connected, but this is not the only way to do it. 101 00:07:23,740 --> 00:07:31,630 ‫We can, of course, do it this way so we can create a student lecture object called ASL, let's say 102 00:07:31,630 --> 00:07:36,550 ‫Tony, which is a type student lecture like that. 103 00:07:36,550 --> 00:07:38,200 ‫Then we can say ASL. 104 00:07:38,230 --> 00:07:55,780 ‫Tony has the student of Tony, then ASL, Tony has the lecture ID of history dot ID and we can go ahead 105 00:07:55,780 --> 00:08:04,450 ‫and apply that data context, dot student lectures insert on submit and it will be ASL. 106 00:08:04,450 --> 00:08:09,460 ‫Tony And actually it's not a lecture here, but it is lecture ID like that. 107 00:08:09,460 --> 00:08:14,440 ‫So now the lecture ID is fine with history ID and student is fine with Tony. 108 00:08:14,440 --> 00:08:22,090 ‫But of course I could have used Tony Dot ID here as well, so I could have said okay, I also want to 109 00:08:22,120 --> 00:08:30,910 ‫say ASL, Tony DOT student ID is going to be Tony Dot ID, but the cool thing is I don't even need to 110 00:08:30,910 --> 00:08:31,360 ‫do that. 111 00:08:31,360 --> 00:08:38,740 ‫So as long as I just give him the student, student contains the ID and student contains the lecture 112 00:08:38,740 --> 00:08:39,550 ‫now as well. 113 00:08:39,550 --> 00:08:41,350 ‫So that's pretty cool. 114 00:08:41,350 --> 00:08:43,600 ‫So now we can go ahead and execute that. 115 00:08:43,810 --> 00:08:45,520 ‫We need to submit that. 116 00:08:45,520 --> 00:08:48,130 ‫But well, I'm going to keep it simple. 117 00:08:48,130 --> 00:08:50,980 ‫I'm going to add another student lecture. 118 00:08:50,980 --> 00:08:55,420 ‫So I'm going to copy that line of code and I'm going to put it on at the bottom of it. 119 00:08:55,420 --> 00:09:01,360 ‫And in this case, it's a Layla or Layla, how I called her. 120 00:09:01,390 --> 00:09:03,760 ‫She has history as well. 121 00:09:03,760 --> 00:09:04,780 ‫So there is Layla. 122 00:09:04,840 --> 00:09:06,100 ‫She is only history. 123 00:09:06,100 --> 00:09:07,840 ‫Then there's Carla, she is only math. 124 00:09:07,840 --> 00:09:10,120 ‫And then as Tony, he likes to study hard. 125 00:09:10,120 --> 00:09:11,710 ‫He has math and history. 126 00:09:12,070 --> 00:09:12,640 ‫All right. 127 00:09:12,640 --> 00:09:15,430 ‫So now we can go ahead and submit that. 128 00:09:15,430 --> 00:09:23,020 ‫So data, context, dot submit changes and we can show that on our grid. 129 00:09:23,020 --> 00:09:32,410 ‫So item source is going to be data, context, dot lecture or student lectures like that. 130 00:09:33,100 --> 00:09:33,640 ‫All right. 131 00:09:33,640 --> 00:09:40,810 ‫So now let's call this insert student lecture association method because we have inserted the lectures 132 00:09:40,810 --> 00:09:41,320 ‫already. 133 00:09:41,320 --> 00:09:44,170 ‫So they are they're in the database now. 134 00:09:44,170 --> 00:09:44,950 ‫Let's run it. 135 00:09:50,630 --> 00:09:50,930 ‫All right. 136 00:09:50,930 --> 00:09:56,000 ‫So now let's assume we want to get the university of a specific student. 137 00:09:56,000 --> 00:09:59,690 ‫So we want to know the name of the University of a specific student. 138 00:09:59,690 --> 00:10:04,710 ‫So let's do that public void, get left. 139 00:10:04,730 --> 00:10:13,610 ‫Or this one, get univer city University of Tony. 140 00:10:13,610 --> 00:10:16,970 ‫So I want to know at which university is Tony. 141 00:10:17,180 --> 00:10:19,520 ‫And I can do it in multiple ways. 142 00:10:19,520 --> 00:10:24,740 ‫Of course I could use SQL code or stuff like that, but I'm going to keep it simple. 143 00:10:24,740 --> 00:10:28,460 ‫I'm just going to use objects here, link objects, and that's pretty cool. 144 00:10:28,460 --> 00:10:39,110 ‫So I'm going to use student Tony who is the data context and here students but first so I'll take the 145 00:10:39,110 --> 00:10:44,330 ‫first student who has the name of Tony. 146 00:10:44,330 --> 00:10:59,090 ‫So name equals Tony and then I need to have a university and that will be Tony's university and it should 147 00:10:59,090 --> 00:11:03,200 ‫be Tony Dot University and that's it. 148 00:11:03,200 --> 00:11:11,930 ‫So now this is this university or Tony's university contains the university object that Tony Tony has 149 00:11:11,930 --> 00:11:13,520 ‫or where Tony is. 150 00:11:14,540 --> 00:11:20,120 ‫And now what we can do is we can show that on our main data grid. 151 00:11:20,120 --> 00:11:25,460 ‫So main data grid items source is equal to Tony's university. 152 00:11:26,270 --> 00:11:27,500 ‫Well, it doesn't work. 153 00:11:27,500 --> 00:11:28,400 ‫And why is that? 154 00:11:28,400 --> 00:11:31,580 ‫Because Tony's universities of type university. 155 00:11:31,580 --> 00:11:34,730 ‫But item store is an I enumerable. 156 00:11:34,730 --> 00:11:43,130 ‫So even though Tony's university is just one object, we still need to create a list of universities. 157 00:11:43,130 --> 00:11:52,220 ‫So let's create a list called universities, which will be a new list of university like that. 158 00:11:52,520 --> 00:12:03,200 ‫So now we can use this list and add our Tony's university to that list, and we can now finally use 159 00:12:03,200 --> 00:12:04,220 ‫universities. 160 00:12:04,220 --> 00:12:11,780 ‫So this list, which can be used as an I enumerable, it's a system that collection and we can use that 161 00:12:11,780 --> 00:12:15,560 ‫here for the main data grid item source. 162 00:12:15,560 --> 00:12:20,600 ‫So now we can go ahead and display the university where Tony is. 163 00:12:20,600 --> 00:12:24,890 ‫And in order to do so, we need to call this method here. 164 00:12:24,890 --> 00:12:32,690 ‫So I'm going to use get University of Tony and I'm going to comment out the insert student lecture associations 165 00:12:32,690 --> 00:12:33,830 ‫that we had before. 166 00:12:33,860 --> 00:12:39,170 ‫So if I run that again, I will see the Uni of Tony. 167 00:12:39,800 --> 00:12:42,560 ‫Now let's check it out and we see Yale. 168 00:12:42,590 --> 00:12:49,190 ‫All right, so Tony's university is Yale, so you could use that data and we'll work with it, right? 169 00:12:49,190 --> 00:12:55,760 ‫So you could get the ID or if there is more information about the university, let's say like amount 170 00:12:55,760 --> 00:13:02,720 ‫of students or amount of professors there or when it was founded, all those kind of things, then you 171 00:13:02,720 --> 00:13:05,420 ‫would have all of those information in that table. 172 00:13:05,420 --> 00:13:09,680 ‫In our case, it's very basic because university only has the ID and the name. 173 00:13:09,680 --> 00:13:16,010 ‫But the cool thing is with those objects, they contain everything that this specific data type has. 174 00:13:16,010 --> 00:13:21,050 ‫So in university, if it had all of those things, we would have all of those things in Tony's university. 175 00:13:21,290 --> 00:13:24,410 ‫So that's very, very useful. 176 00:13:24,950 --> 00:13:25,490 ‫All right. 177 00:13:25,490 --> 00:13:27,650 ‫So now a little challenge for you. 178 00:13:27,680 --> 00:13:32,390 ‫Get Tony's lectures and in this case, use a query, please. 179 00:13:36,190 --> 00:13:36,790 ‫All right. 180 00:13:37,210 --> 00:13:38,710 ‫So let's create a new method. 181 00:13:39,910 --> 00:13:41,350 ‫Public void. 182 00:13:41,380 --> 00:13:46,600 ‫Get all lectures from Tony. 183 00:13:49,850 --> 00:13:52,610 ‫And in here I want to have the student, Tony as well. 184 00:13:52,610 --> 00:13:57,200 ‫So I'm just going to copy that code because well, I need the Tony object anyways. 185 00:13:57,200 --> 00:13:57,590 ‫Right. 186 00:13:57,590 --> 00:13:59,630 ‫So now I want to see all of his lectures. 187 00:13:59,630 --> 00:14:04,580 ‫And as you know, this was the guy who has a very hard work ethic and he has two different subjects. 188 00:14:04,580 --> 00:14:08,690 ‫So what we need to do is do the following. 189 00:14:08,690 --> 00:14:21,800 ‫So Tony's lectures is going to be from s l standing for student lectures in Tony Dot student lectures, 190 00:14:23,090 --> 00:14:27,860 ‫select l Dodd lectures or lecture. 191 00:14:28,850 --> 00:14:29,150 ‫All right. 192 00:14:29,150 --> 00:14:30,380 ‫So that's the other approach. 193 00:14:30,380 --> 00:14:33,800 ‫That's an alternative of getting a specific lecture. 194 00:14:34,220 --> 00:14:41,030 ‫And now we can use that in our main data grid as items source. 195 00:14:41,120 --> 00:14:44,570 ‫And that will be our Tony's lectures. 196 00:14:45,890 --> 00:14:46,130 ‫All right. 197 00:14:46,130 --> 00:14:52,130 ‫So you see there are multiple different approaches to doing things and this one seems to be shorter 198 00:14:52,130 --> 00:14:53,150 ‫and that's totally fine. 199 00:14:53,150 --> 00:14:55,340 ‫So let's call that one again. 200 00:14:56,180 --> 00:15:06,260 ‫So instead of get University of Tony, let's get lectures from Tony now let's call it again. 201 00:15:06,260 --> 00:15:12,890 ‫And we should see math and history and see math and history are displayed here. 202 00:15:12,890 --> 00:15:21,320 ‫So the math and history with the ID one and two, these are the lectures that our buddy has so that 203 00:15:21,320 --> 00:15:24,380 ‫our friend Tony has. 204 00:15:24,380 --> 00:15:28,460 ‫But you can see here the student lectures are also displayed and they are empty. 205 00:15:28,460 --> 00:15:34,070 ‫So this information, this object doesn't have any information that are displayed here. 206 00:15:34,070 --> 00:15:40,430 ‫But what is important for us, and that's what we need here, are the actual names of the lectures that 207 00:15:40,430 --> 00:15:41,420 ‫the student has. 208 00:15:41,660 --> 00:15:41,990 ‫All right. 209 00:15:41,990 --> 00:15:44,660 ‫So we could display them in a much nicer way. 210 00:15:44,660 --> 00:15:51,920 ‫And then I could see, okay, Tony has all of these lectures, and I could, for example, add his marks 211 00:15:51,920 --> 00:15:56,030 ‫here next to it or his performance in general and those kind of things. 212 00:15:56,030 --> 00:15:56,660 ‫All right. 213 00:15:56,840 --> 00:16:03,950 ‫So that's quite a lot about using SQL and using Link already. 214 00:16:03,950 --> 00:16:06,560 ‫But in the next video we're going to do even more. 215 00:16:06,560 --> 00:16:11,690 ‫So we're going to add several more methods which do quite some cool things because we haven't seen how 216 00:16:11,690 --> 00:16:18,170 ‫to update, we haven't seen how to delete specific users, how to, for example, get all lectures from 217 00:16:18,170 --> 00:16:20,810 ‫a specific university, all those kind of things. 218 00:16:20,810 --> 00:16:22,940 ‫So there's plenty to learn still. 219 00:16:22,940 --> 00:16:25,010 ‫So see you in the next video.