‫Welcome back.
‫In this video, we are going to check out all the lecture stuff.
‫So, first of all, we're going to add lectures.
‫So insert them into our tables and then we're going to create this associative table.
‫Well, we're going to add information to this sort of table called the Student Lecture.
‫So I'm going to create a new method, public void, insert lectures, and you might know how to do that.
‫You might remember how to add lectures or add something to a table so you can try yourself.
‫You can pause the video and try to add lectures yourself.
‫You can even think of your own lectures.
‫All right.
‫I'm going to just use the quick and dirty version.
‫So data, context, dot lectures and now it's complaining.
‫Oh, man, there are no lectures.
‫What the hell do you want from me?
‫I don't know.
‫What is lecture or lectures?
‫Method or class should be.
‫So what I'm going to do is I'm going to add lecture like that in here.
‫So the were now this lecture table.
‫Can go ahead.
‫So let's go into the CSS file and here lecture now should come up within a couple of seconds and then
‫we are like, cheers, there it is, insert on submit and I'm going to add a new lecture with the name
‫of math.
‫So there is a lecture called math and you might have thought of your own lectures.
‫So I'm going to add another lecture in here, and the next one will be something like history.
‫All right, now let's add those to the table.
‫So data, context, don't submit changes.
‫And finally update our main data grid and items source because I want to see the different lectures
‫that I have.
‫So data context, start lectures.
‫All right.
‫So now let's call this method instead of our insert student method.
‫So insert lectures like that.
‫All right.
‫So let's run the code, and we should see the two lectures that we have set and that we are ID one math
‫and ID two history.
‫All right, now we need to have this associative table because we have created this associative table,
‫student lecture, and it combines students with lectures.
‫So the idea of a student and the idea of a lecture are connected to each other.
‫So we know which student has which lecture.
‫So let's say not every student has math and every student has history.
‫So in order to do that, we're going to create another method with this associative table public void,
‫insert student lecture associations like that.
‫So in here what I want to do, I want to add multiple students and multiple lectures.
‫So in fact, all of my four students and all of my two lectures and I want to use them as objects in
‫order to create those student lecture connections.
‫So please go ahead and try to create all the student objects and all the lecture objects that we have
‫in our table.
‫I hope you tried it.
‫So first of all, I want to have a student, which I'm going to call Carla and she is a data context
‫dot students dot first.
‫So I'm going to get the first student and I'm going to use the same approach that we have used with
‫the universities so equals here.
‫It's Carla like that.
‫And this approach here that we have is exactly the same that we used here with the universities.
‫So I'm getting the first student in my students data context.
‫So here, which has the name or what name equals to Karla and I do the same thing with my other students.
‫So the other one was Tony.
‫And there the name was Toni.
‫Then we had Layla, which I accidentally called Layla, so I'm going to call her Layla here as well.
‫And then we had James, which I accidentally called James.
‫So I'm going to search for James here as well.
‫And that's the students and now the lecture.
‫So if you didn't manage to get the lectures as well or the students either, then please try to do that
‫with the lectures now, because now you see how it's done with the students.
‫Okay.
‫So lecture and it was math, which is data context that lectures thought first.
‫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
‫was math.
‫So that's our lecture math.
‫And now let's create the second lecture, which was history.
‫And this one will be history like that.
‫And now we can create student lectures.
‫So that's pretty decent.
‫We can go the data context and here.
‫Student Oh, it doesn't show me student lectures.
‫Why is that?
‫Well, you hopefully know it's because we don't have it here.
‫So let's create a student lecture and put it in here.
‫And as you can see, student lecture is connected with student and lecture, so let me drag them correctly.
‫So you see, the student is connected to university, so a student is in one university, but a university
‫has multiple students.
‫Then a student's a student has student lectures.
‫Well, it has lectures, but they are both connected to the student lecture table.
‫So lecture and student are connected in student lecture, as you can see, is because of the student
‫ID and a lecture ID.
‫That's why they are connected here.
‫So now what we can do is create a student lecture.
‫So I'm going to use data context student or yeah, it's actually student lectures like that and insert
‫on submit.
‫And what do I want to submit.
‫Well, a new student lecture entity and that will be with the student, let's say this one is with Carla
‫and she has a lecture called math.
‫So now we're not saying called math, but we're actually saying the math object.
‫So the object, Carla, and the object math are connected and object Carla is of type student and object
‫lecture or math as of type lecture.
‫So now we're connecting them in this one line.
‫Now let's do it again with another student and another lecture.
‫So let's say Tony also has math.
‫So now we have those two connected, but this is not the only way to do it.
‫We can, of course, do it this way so we can create a student lecture object called ASL, let's say
‫Tony, which is a type student lecture like that.
‫Then we can say ASL.
‫Tony has the student of Tony, then ASL, Tony has the lecture ID of history dot ID and we can go ahead
‫and apply that data context, dot student lectures insert on submit and it will be ASL.
‫Tony And actually it's not a lecture here, but it is lecture ID like that.
‫So now the lecture ID is fine with history ID and student is fine with Tony.
‫But of course I could have used Tony Dot ID here as well, so I could have said okay, I also want to
‫say ASL, Tony DOT student ID is going to be Tony Dot ID, but the cool thing is I don't even need to
‫do that.
‫So as long as I just give him the student, student contains the ID and student contains the lecture
‫now as well.
‫So that's pretty cool.
‫So now we can go ahead and execute that.
‫We need to submit that.
‫But well, I'm going to keep it simple.
‫I'm going to add another student lecture.
‫So I'm going to copy that line of code and I'm going to put it on at the bottom of it.
‫And in this case, it's a Layla or Layla, how I called her.
‫She has history as well.
‫So there is Layla.
‫She is only history.
‫Then there's Carla, she is only math.
‫And then as Tony, he likes to study hard.
‫He has math and history.
‫All right.
‫So now we can go ahead and submit that.
‫So data, context, dot submit changes and we can show that on our grid.
‫So item source is going to be data, context, dot lecture or student lectures like that.
‫All right.
‫So now let's call this insert student lecture association method because we have inserted the lectures
‫already.
‫So they are they're in the database now.
‫Let's run it.
‫All right.
‫So now let's assume we want to get the university of a specific student.
‫So we want to know the name of the University of a specific student.
‫So let's do that public void, get left.
‫Or this one, get univer city University of Tony.
‫So I want to know at which university is Tony.
‫And I can do it in multiple ways.
‫Of course I could use SQL code or stuff like that, but I'm going to keep it simple.
‫I'm just going to use objects here, link objects, and that's pretty cool.
‫So I'm going to use student Tony who is the data context and here students but first so I'll take the
‫first student who has the name of Tony.
‫So name equals Tony and then I need to have a university and that will be Tony's university and it should
‫be Tony Dot University and that's it.
‫So now this is this university or Tony's university contains the university object that Tony Tony has
‫or where Tony is.
‫And now what we can do is we can show that on our main data grid.
‫So main data grid items source is equal to Tony's university.
‫Well, it doesn't work.
‫And why is that?
‫Because Tony's universities of type university.
‫But item store is an I enumerable.
‫So even though Tony's university is just one object, we still need to create a list of universities.
‫So let's create a list called universities, which will be a new list of university like that.
‫So now we can use this list and add our Tony's university to that list, and we can now finally use
‫universities.
‫So this list, which can be used as an I enumerable, it's a system that collection and we can use that
‫here for the main data grid item source.
‫So now we can go ahead and display the university where Tony is.
‫And in order to do so, we need to call this method here.
‫So I'm going to use get University of Tony and I'm going to comment out the insert student lecture associations
‫that we had before.
‫So if I run that again, I will see the Uni of Tony.
‫Now let's check it out and we see Yale.
‫All right, so Tony's university is Yale, so you could use that data and we'll work with it, right?
‫So you could get the ID or if there is more information about the university, let's say like amount
‫of students or amount of professors there or when it was founded, all those kind of things, then you
‫would have all of those information in that table.
‫In our case, it's very basic because university only has the ID and the name.
‫But the cool thing is with those objects, they contain everything that this specific data type has.
‫So in university, if it had all of those things, we would have all of those things in Tony's university.
‫So that's very, very useful.
‫All right.
‫So now a little challenge for you.
‫Get Tony's lectures and in this case, use a query, please.
‫All right.
‫So let's create a new method.
‫Public void.
‫Get all lectures from Tony.
‫And in here I want to have the student, Tony as well.
‫So I'm just going to copy that code because well, I need the Tony object anyways.
‫Right.
‫So now I want to see all of his lectures.
‫And as you know, this was the guy who has a very hard work ethic and he has two different subjects.
‫So what we need to do is do the following.
‫So Tony's lectures is going to be from s l standing for student lectures in Tony Dot student lectures,
‫select l Dodd lectures or lecture.
‫All right.
‫So that's the other approach.
‫That's an alternative of getting a specific lecture.
‫And now we can use that in our main data grid as items source.
‫And that will be our Tony's lectures.
‫All right.
‫So you see there are multiple different approaches to doing things and this one seems to be shorter
‫and that's totally fine.
‫So let's call that one again.
‫So instead of get University of Tony, let's get lectures from Tony now let's call it again.
‫And we should see math and history and see math and history are displayed here.
‫So the math and history with the ID one and two, these are the lectures that our buddy has so that
‫our friend Tony has.
‫But you can see here the student lectures are also displayed and they are empty.
‫So this information, this object doesn't have any information that are displayed here.
‫But what is important for us, and that's what we need here, are the actual names of the lectures that
‫the student has.
‫All right.
‫So we could display them in a much nicer way.
‫And then I could see, okay, Tony has all of these lectures, and I could, for example, add his marks
‫here next to it or his performance in general and those kind of things.
‫All right.
‫So that's quite a lot about using SQL and using Link already.
‫But in the next video we're going to do even more.
‫So we're going to add several more methods which do quite some cool things because we haven't seen how
‫to update, we haven't seen how to delete specific users, how to, for example, get all lectures from
‫a specific university, all those kind of things.
‫So there's plenty to learn still.
‫So see you in the next video.