داستان آبیدیک

enumerable


فارسی

1 کامپیوتر و شبکه:: enumerable

so this listen I'm going to make one big change to kind of work with this get all customers and I'm going to jump into the customer repository and the read all is I'm going to change that from being a list right here into being an ienumerable not equatable enumerable there we go I an ienumerable is actually one of the interfaces that a list inherits or uses okay so ienumerable if i go back to the customer repository here it's still just returning a list i want that guy to return an animal here at the implementation as well so let me just try and show you if I jump into the list do go to Declaration right here for the list you'll see that in the top you can see that it uses the I collection interface and the ienumerable interface but why do we care why not just use the list as it is well we're going to use start using link soon and link ll inq link you or link we're going to use that to make some pretty cool queries and the cool thing about link is that as long as we're making a query until we call kind of an execute command we can build huge queries especially against SQL later on so we can build a query and it's not until we say to list that we're actually going to execute the entire query so let me show you what I mean here is the final thing so jumping back to the service now I don't want to change this guy cuz this is the service layer and here it's a-okay to return a list cuz now we are very concrete I need a list I don't need an enumerable which can be other things than a list specifically I need a list and that's okay in the service layer cuz now we're talking business logic up here so let's try and actually use our beautiful beautiful repository right here the customer repo to get all read all that's what we called it and notice right here I'm getting an error now and that's because list is not the only guy using the interface ienumerable so we have to be you would end up spending way too much time getting the data from the database so when we did this when we did the to list right here that was actually the time where we converted a query which is this guy you know the ienumerable right let's just mouse over right here you can see ienumerable as soon as I called the to list I actually said I know what I want to do later but as soon as I call this guy I actually execute that query meaning that when I did this I was actually only setting up so when I did this part I was just setting up what I wanted to do but as soon as I actually did the two lists I executed what I wanted to do we go to time more into this but this is one of the powers of link now right below it I just started a new method right here because I only want to get all my users by first name right here are my customers so notice right here I have a list but right now the list is only an enumerable so that pretty much means that right here I have not executed any query so not execute anything yet right so that's kind of important to know then I go down here and I can say let's just return the list but I cannot do that until I say to list right but now I've actually execute it and gotten the data I'm still getting all the customers right now and that's not what I wanted but just to let you know nothing has been executed yet here I bet I asked for all the customers might not be th important with a small database in-memory like we have right now with a huge database this makes sense so let's try and do something let's say instead of getting every body I actually want to say I only will get want to get the ones where so I used to wear clothes with a link and then I say for each customer not there we go customer and here I use a lambda expression I want to kind of use that customer first name to check if that is equal to the name that I'm getting from the outside right here okay let me just move that up one line so again it's easy for you to see this cut that let's make a query continued right here and then put it in there okay so what's important to notice right here is I've just taken a where clause right here and it's actually still not executed I'm still building a query I'm still preparing something but already at this point you'll notice that if this was sent to an SQL database I could send in I only want customers where last name first name equals the name I'm sending in right so it's already a smaller data set if I'm gone now and I feel that I'm happy I can just say query continued to list and the query is executed da right so this is very powerful this means that I can actually start defining what I want to do and I could keep going here I could also order them all let's just say Auto buy and let's just put in again the customer like this and say customer dot name if I want to order by the name there we go still queries not executed I'm just preparing a statement right and in the end when I'm done I'll just execute it by calling the to list so this is why this is so important notice right here that I can now start making some crazy crazy queries if I want to but I don't have to have a new and new query inside the repository every time right if I was going to make the good old list statement inside the repository I would have to make a new query in the repository saying get all by first name get all by first name right then I would have to make a new one get all by first name where ID equal to well get all by blah-blah-blah-blah that's not the idea with the repository the repository is just going to grab the data that's the goal for that one so now I made a very generic repository that we can go and make completely generic later and I let the service take care of the business logic of saying get all my first name by actually getting all the customers and then filtering them but don't go to the database until you call this to list in the end so I don't know if this makes sense yet but as we start working with the NT framework I'm sure it will the last thing I just want to do is open this up in the interface just to kind of give it the axis so I'll just go to the service and just add one more up here get all customers because I want that in my interface as well that was it for this lesson now we've just changed inside the repositories we've gone and changed into enumerables and I've also shown you kind of two ways of using the enumerable and we're not going to execute anything until we do the two lists and they're all the commands for that as well just to wrap this up right here let's just try and jump into link tutorial on tutorials teacher calm and just scroll down here are all the different things we can do with link before we actually make it into a list we can count that's actually also going to be an execution we can call first a default that's also an execution and there's so much we can actually do the link and we'll start looking into that in upcoming lessons have fun

واژگان شبکه مترجمین ایران


معنی‌های پیشنهادی کاربران

نام و نام خانوادگی
شماره تلفن همراه
متن معنی یا پیشنهاد شما
Captcha Code