SQlite Database in Visual Studio 2019 | Entity Framework Core

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back once again in this video we will look at sqlite database inside of visual studio 2019 but before we get started please make sure you subscribe to the channel if you haven't so let's get to it then so sqlite is a relational database management system which is contained in the c library sqlite is not client server database but rather embedded into the end program sqlite is a popular choice as embedded database software for local client storage in application software such as web browser mobile phone applications desktop applications etc secular is arguably the most widely deployed database engine it is it also has bindings to many programming languages such as c-sharp which we're going to look at in this video so so in this video we will precisely look at sqlite entity framework called database provider so we will actually look at sqlite in the lens of a of an entity framework developer so we we get started by actually clicking on the file it's the start window to create new project so here we're going to select the console app dot net call the once that bit is selected then we can click on the nest so here obviously you can configure your project details but we're not going to look too much into that so we click on the create so while it's being loaded so the sqlite entity framework called database provider so this database provider allows entity framework call to be used with simple lies and this is also maintained as part of the entity framework core stack so as you can see here now we've actually got um the blank console lab created so what we would do is we're going to add a new a new class so it's public class now we're going to call it products and we're just going to have like three attributes so we're gonna have an int which is a product id and we're gonna get string which will be the product name then we're going to get double which will be the price so here of course is a product id so this we will move this bit here to product.cs so here what we do so what we do is we actually right click on the dependencies then we go to manage new get packages so we come inside and install i'm in the browse bit here so what we do is we are going to enter microsoft dot entity framework called dot sqlite so that is normally the first one so it's microsoft entity framework called sqlite so we actually install this bit here so we click ok and we accept so once we've got the package installed we're just going to close the new get package then the new year's package manager then we're going to create a new class it's a public class so we're going to say sqlite tv contest so this actually inherits db contest so this will be on the microsoft dot entity framework call so what we do is we move the sql like db contest to sqlite db contest.css so that's that's the class that is actually created here now so what we do is we put public creator property db set property product and we can say products and it's a get set so we're going to override two methods so the first bit is protected override on configuring so we're going to configure the application to use um sql lite so what we do is um the options builder dot use equal light so as you can see here we can see this bit here now so this is what we do put the file name here so this will be the name of the database is equal to so we're going to call this a circle light db one yeah then we're going to span this with an option here option okay so inside here we're just going to put a semicolon here that will press end so here this is what we're going to put here we're going to put option dot migration assembly so we're going to say assembly so here we're doing a bit of reflection assembly dot get executed assembly so here the dot full name so we get the full name of the executed assembly so that's all we're going to do for this bit here so the next bit is of course we create another overriding method which is a protected override on model creating so here we can set our database table so here we can say model builder dot entity so the entities of course products the product objects so we could say to table so create a products so we put a product table and then the schema so we're just going to put test just test for the schema so the next bit is is the same model builder dot entity so the products so in here we're gonna say entity so we're going to put some options inside this entity here so we're going to say entity so we're going to set the primary key as key so this will be k k dot product id so that will be the key then entity entity dot we set the index has in this so we could say um i for the index i dot product name and then we set it to unique it's unique so that's all we're going to need for the the db contest so we come inside the program so here we're going to make a static async task so that's we're going to change the main static async task yeah so we're going to leave the hello world here so this is what we're going to do so we're going to start with the variable this will be our db name this will be equal to so we come inside the db contest so the db name that we set here we copy this db name so we set it here we put it we paste it here dot db put a dot db link i mean extension then we could say if file so file in system.io dot assist so put the db name if file is is then we can say file dot delete don't delete the db name otherwise we continue so we can say await using so we start we create a new variable are we to using variable so this will be a db contest is equal to new sqlidb contest so we can say await db contest database dot ensure created async then we can say again await db contest dot products dot ad range so we're gonna add some products async so we can say that we can create a new product array here so here we can add some products so new products so inside here you can add a prototype not product id product name apple and a price 10.99 so what we do is we're just going to copy and paste them all over we're just going to make free just change the prices and the names so we're just going to make this big mango and banana so that's all we have for here now so now we can say okay so now after the task you can say await db db contest dot save changes async so that's what we're going to do for here now so now we can come down a bit and look inside the database and get the information so we could console.rightline getting database data so we can do that by say db contest dot products so we check whether it's not now dot convert to list dot for each so we look through so p for product then we can print them out so we can say we can put the product name first so we can say p p dot product name and then the price we can say p dot price then we can convert it to money so that's that's all we gonna do for the video now so now i'm just gonna run it so we can see what actually comes out of it so let's hope everything works out so i'm just gonna put console.readline here so that we can see what is actually going on so i'm just gonna run it so fingers crossed the whole thing works i'm gonna pause it while the whole thing runs so as you can see here now we've been able to create the database and actually get the data from the sqlite database so what we do is we're just gonna come inside the solution now we come inside all files show all files so we come inside the bin and debug the network 3.1 we scroll down we look for you're going to look for the db creator so as you can see top here sqlite db1 that's the one that is created now so i'm just going to leave it here and i hope you actually explore the sqlite further in terms of using it for other applications so once again if you haven't subscribed to the channel please make sure you do because i've got lots of videos coming up and i hope you'll have a lovely morning evening afternoon wherever you are peace
Info
Channel: Hacked
Views: 40,673
Rating: undefined out of 5
Keywords: sqlite, java, sql, sqlite3, sqlite database, sqlite tutorial, sqlite database visual studio, sqlite android tutorial, sql database relationships, relational database visual studio, database management system, t-sql visual studio, visual studio 2019 sqlite, sqlite database project, c# sqlite tutorial, c# sqlite entity framework, coding, programming, software engineering for beginners, database development for beginners, embedded database, embedded database c
Id: MQNFjYOluow
Channel Id: undefined
Length: 16min 45sec (1005 seconds)
Published: Sat Jan 30 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.