Domain Introduction and Entity Framework Setup - FULL STACK WPF (.NET CORE) MVVM #1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today we're starting a brand new series this is full-stack WPF mvvm and what the heck does that mean well my full stack I pretty much just mean that we're gonna be doing all the development from the database layer all the way to the UI layer some of the things that we're gonna be working with are any D framework for our database interaction we're going to be using WPF for the UI of course and along with that we're gonna be using mvvm architecture and model view viewmodel it's gonna help us separate our concerns with the UI and the logic for the UI and then along the way we might also do some unit testing and of course we're gonna be calling an API as well so now that we have an idea of what this what we're going to be working with well what's this application gonna do what are we building and I've seen a lot of tutorials everyone does like a blog is some kind of like grocery store or something like that so I decided to take it up a level a little bit and we're gonna be doing a trading application you know trading stocks all those things so this is a little database diagram so this is what our database is gonna look like we're gonna have users so of course people are gonna be able to log in log out register for our application it's gonna support multiple users a user is gonna have an account which will have a balance so that balance is how much buying power you have and then we're gonna have transactions in the database so whenever you purchase a stock it'll go into the database so that's our database we also have a domain which kind of reflects the database is pretty much the user the account the transactions but what we're going to be doing is we're gonna be using these asset transactions to calculate how much what your like total assets are and I don't want to get too far into this because we're gonna actually be implementing it in code so if it doesn't make sense right now don't worry we're gonna implement everything and it'll make perfect sense along the way and then we're also gonna have some service classes in general just interfaces so I have this generic data service that will interface with our within any framework actually and then we'll have some buy stock service so stomache service that's when you want to buy still stocks I stock price service so that's getting the price of stocks that's going to be called from the API and all three of these will be called from the API as well all right so I have a blank solution here absolutely nothing in here just simple trader and first thing let's set up a class library so we're gonna be doing dotnet core class library and we're gonna call this simple trader dot domain there we go we got a fresh project and this project is just gonna have all of our domain logic inside of it so our first thing we want to do is obviously delete this class one because we want it and I'm gonna make a new folder called models so this is gonna have all of our domain models inside of it and let's actually bring up that Visio diagram again and I want to do like side by side here so we're gonna actually just implement these UML diagrams that I have so we're gonna have a user we're gonna have and account we're gonna have a let's just do asset transaction for now and we'll leave all the other stuff well let's let's do stock - we're gonna have a stock all right so let's implement our user this should be pretty simple so we're gonna have a public property for the ID we're just gonna do some simple getters and setters right now we're gonna have a string for the email we're gonna have a string for the username and that's actually all we're gonna have alright so there's our user let's get rid of that for now and let's go to our account now so again this just a simple object as well we'll have an int for the ID we'll have a user this is going to be that account holder we're gonna have a balance and we'll have a list of asset transactions how doesn't know what that is oh because I made it whoops okay and that's gonna recall it as those transactions so don't move it okay what's it saying you okay so it's just complaining is this in public but now it is and asset transaction it's gonna have an ID as well it's gonna have an account associated with it we're gonna have a boolean is purchase I really don't like the name of that I'm really thinking like should it be an M I don't think so because it's either buy or sell but is purchase I don't know if anyone has better ideas instead of is purchase let me know in the comments and then we're gonna have a stock associated with this and lastly an int for the amount of shares they'll actually call this amount of shares or share or just why not just shares I don't understand okay I was just complaining okay so cuz stock isn't public okay it's now lastly we'll have our stock and this is gonna be a it's pretty much gonna be a value object so it's just gonna have a symbol and the price per share okay so my value object I pretty much just mean it doesn't really have identity its identity is made up of its values that's what make alright its values make it unique that's how we'll describe that all right so now we have our domain fill it out this isn't really like everything but it's pretty much almost everything alright so now we're gonna start implementing these interfaces well those are going to go in our domain too and we'll have a separate folder for those called services and we're not going to implement all of these I think the only one I really need right now is this ID to service because my main goal right now is just to get the database set up eventually and we don't really need all of the other demand logic we pretty much just want to have an interface for accessing data so it's going to be an ID to service and it's going to be generic so we can use it for any entity and some of the methods it's gonna have it's just gonna have generic crud stuff and one thing I want to do is I want to make these tasks now making them tasks so I want them to be able to be called asynchronously with a syncing it wait so this is going to be returned a list of T and we're gonna call that get all got an import task control dot enter and we have a task of ta get that's gonna be like a gift by ID and then we'll have a create so that's gonna be tasks of tea as well so whenever you create something it'll return the created item you can just return the ID but I think in the past I've had trouble with that so I think just to be safe I've just started returning the entire object and from there I just work with that call that tea entity and then we'll do an update as well again I'm returning the entire object and it will have the ID and the new value and then we'll have it delete as well and that's just gonna read it true false all right so that's pretty much our generic data service all right so that's enough work in our domain layer for now the next thing I want to do is start setting up any framework and what we're going to do is we're going to create a new project and this is going to be dot in that core once again and we're gonna call it simple trader dot entity framework alright let's get rid of this class one of course let's go into our nougat packages and we're gonna browse for and any framework now there's two options here two main options this is actually for dotnet framework but we are using dotnet course so we're going to use this and it defaults to this version 3.0 but I'm using dotnet core 2.2 so I'm not gonna select 3.0 I'm just like 2.0 and let's just install that I accept alright so we got any framework or in here maybe later down the road we'll do an update try and update to the latest version it's not in that core but for now we're just going to be using version 2.2 alright so we got any framework installed first thing we want to do is let's create a new class we're gonna call this the simple trader dbcontext and this is going to be a public class so we're going to inherit from dbcontext which is part of any new framework or so what this class is going to do is it's going to manage our interaction with the database within a framework so to do that we're gonna have to tell it what kind of entities that we want to store in our database and that's going to be done through DB sets so we're gonna have a TV set right here that's generic so this is where we tell it what nd we want and we're gonna be doing what's our models here so it's through users for now what was called this is users and that's just curious simple property but we're gonna have to import user and that's going to come from our simple trader domain project so of course we just control dot it'll add a reference to that project and that it will import the namespace as well so now if we go to our dependents is projects we have a reference to our domain layer so now we have users we're gonna have another DB set for accounts I'll call this accounts and then we'll have another DB set for asset transactions so again going back to our UML diagrams it's basically just this alright so now we have to actually generate our database but to do that we're gonna have to be using migrations of course and when we generate those migrations and run those migrations we're gonna have to provide a connection string and that connection string is going to go into our simple trader DB context right here so we're gonna override 1 configuring and we're gonna say options builder dot use I want to use sequel server that's what I want to do but to do that we're gonna have to add another manage another new get package so it's going to manage and you get packages and let's search for sequel server yeah okay so we have anything from record that sequel server and we need to install this because our database is going to be sequel server so of course let's do 2.2 install that should be good so now if we come back over here can use sequel server that's like an extension method that that package that we just added brings in and then we just give it a connection string which I have let's just copy that in there so we're gonna be using sequel Express which I've already installed and our database name is going to be simple trader DVD it doesn't like that okay double slash there we go alright so now we need to generate some migrations and run them and to do that we're gonna need another in the good package this time we're gonna be using enemy framework core dot tools so down here version 2.0 let's install that and I accept alright so now we have that we can go into our package manner your package manager console and we can say add migration call this initial hopefully this works so it's doing some stuff okay we have the wrong our starter project has to be this and that should work okay we got a we have to stock requires a primary key to be defined but we don't really want that in the table anyways because if we go back to our Visio as you can see this asset transaction it has in our model it has a stock but we want to actually embed that into the table so we can actually do that in an ad framework and to do that we can go into this we can override this one model creating and we can say model builder model builder dot entity and the entity that way you have that stock a part of is the asset transaction so ask that transaction dot owns one and we're gonna say believe we just type in like a lambda here sir a say first so what this is doing is it's basically telling it that this stock object on our ant asset transaction if we want it to be embedded in the asset transaction table so if we look at stock symbol and price per share are going to be in the table instead of a stock so that might be a little bit confusing to understand but when we generate our database we'll see I'll show you guys what the outcome is so let's give this another shot add migration additional alright it actually worked that's awesome and now all we have to do I believe is update database alright so I was getting errors with update database and it turns out my connection string was wrong and I was putting in the wrong server my correct server is this if you want to find out what your sequel Express server name is you can just go it's a sequel server object Explorer over here view sequel server object Explorer and it just says it bring it up here so local DB for me / MS sequel local DB you just copy/paste that right there and now our connection string is correct and now we can update database and it will work because I already tested it takes a little while and there we go so now let's go back to our sequel server object Explorer I got a bunch of databases in here but if I were refresh I open this back up we now have simple trader DB open that up let's look at our tables we have accounts now let's actually open up all these and make sure that they match what we had plans so for user we have we left out a few things here we left out a password and we left out at date joint so we're gonna have to fix that with migrations and then let's look at asset transactions so we have account ID that's what this show said I can't I do we have symbol price per share shares and I forgot the date process okay so we forgot a few things so let's head back into user and we're just gonna have a date time for date joins and yeah we're gonna have a string for password which we're gonna have to encrypt later so that should be good there let's go into transactions okay so date process is all we need here all right I think that's all we need and we're gonna add migration whoops and we'll call this add dates since we added all this date field so we actually added a password too but whatever okay update database all done let's look at our accounts table should be fine I think our users table changed let's look at that all right so we got did joins we got password and let's look at asset transactions we have date process okay so that's our database our database is set up we have migrations we have a little bit of our domain completed and that is where we're going to wrap up for now thank you guys for watching if you have any suggestions for the series be sure to leave them in the comments leave a like or subscribe for more I hope you guys stick along with this series I'm enjoying it so far it's fun making projects and I hope you guys enjoy it too thank you
Info
Channel: SingletonSean
Views: 43,582
Rating: undefined out of 5
Keywords: wpf, mvvm, easy, hard, difficult, switch, views, microsoft, visual, studio, binding, viewmodel, property, inotifypropertychanged, class, interface, user, control, window, learn, how to, teach, architecture, pattern, new, correct, switching, toggle, button, content, main, command, icommand, programming, tutorial, full, stack, entity, framework, model, dto, dao, data, access, orm, object, core, .net, c#, service, layer, onion, walkthrough, project, finance, stock, trade, trading, development, uml, visio
Id: V9UdD96iTbk
Channel Id: undefined
Length: 21min 30sec (1290 seconds)
Published: Sun Nov 17 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.