Hello friends, welcome to the next slide. In previous lab, we have created the entities which are required for our entity. entity subject and entity student class. Now, we know how to create DB context class. Okay. Then I'm going here and add one new class student DB context okay.
For this class, I hope to inherit from DB context. Now DB context is not present. So I need to include the namespace. You can include this Microsoft dot Entity Framework Okay. Now, in this class, I have to add two properties, one for student and one for subject. So, I create public DVC and table students Now similar I have to create one for subject okay after that I need to register this class gold service okay for what it needs to available total application now where I can add this in, configure service So, yeah, I will add services or add DB context okay.
No DB context which class we have created student DB context for Entity Framework. And it should require for we can write one lambda function where it is include connection string, we use SQL Server, okay for our name so I use youth is good server and now this is not present here. So, I'm going here and add using Entity Framework. Now it is available what it contains it required connection string. So right now we're not defining connection string. So, include only connection string we need to include connection string here okay.
Now it is showing me the error why the statement is cannot be used as a parameter okay so why this is happening? Because we include student context we have created student DB context class. So I need to include this. Now it is not present here so I need to include namespaces Okay, this is for entity Primo. Now here as we are using the SQL Server built in Visual Studio, so I go here and check for SQL Server. Now, here is one instance.
So I need to get the connection string. So this is our connection string, right click Properties you can get connection string. Let's see properties and you can connection string here. So for this I need To include one variable here. So, I declare as connection string and the connection see okay it is showing some error. So, are you at the red symbol now error is gone and this connection string we need to pass here.
So, it will perform connection. But as you can see here, we are not creating our databases. Now we have to create our database. So, how I need to include one constructor here? Okay. One constructor So how am I going to do That that pleasant city or should inherit from this okay.
Now I hope to pass a DB context option and student DB same I pass here and after that here after connection, it's okay or after connection perform, we need to ensure that our databases created orma. So for that purpose we will use database dot ensure created okay so far now this is okay well created DB context class now. We will meet in the next lesson thanks for watching