00:00:05.063 --> 00:00:07.724 The let me know if you're getting background noise or
00:00:07.724 --> 00:00:10.829 anything like that, cause there is some, but I'm trying to use
00:00:10.829 --> 00:00:12.603 NVIDIA, broadcast it around it out.
00:00:12.613 --> 00:00:19.101 So, umm, I'm just going to make like a mock basically task like
00:00:14.723 --> 00:00:15.443 Sounds good to me.
00:00:19.101 --> 00:00:24.373 workflow task kind of thing that returns a list of.
00:00:26.173 --> 00:00:27.433 Unpaid invoices.
00:00:29.273 --> 00:00:30.883 Ohly it's that.
00:00:32.573 --> 00:00:36.632 Ohh, I'm like totally like looking at two different things
00:00:36.632 --> 00:00:37.183 at once.
00:00:37.193 --> 00:00:39.973 Anyways, get unpaid sales invoices.
00:00:41.453 --> 00:00:45.043 They takes an A list of ints.
00:00:45.113 --> 00:00:45.543 Ideas.
00:00:45.553 --> 00:00:49.543 So basically, like I'm just gonna go over ways to like to
00:00:49.543 --> 00:00:52.363 DOS and not to DOS for entity framework.
00:00:54.483 --> 00:00:56.784 And I apologize if I stopped typing cause I'm like looking at
00:00:56.784 --> 00:00:57.193 two things.
00:00:57.363 --> 00:01:01.253 I have a I have a decent reference umm to go off of so I
00:01:01.253 --> 00:01:05.211 guess I'll start with like a very basic like perhaps what
00:01:05.211 --> 00:01:09.033 someone who's new to EF might end up just writing as an
00:01:09.033 --> 00:01:13.264 example query, not necessarily for the specific use case, but
00:01:13.264 --> 00:01:16.403 let's say we were just getting cell go ahead.
00:01:14.893 --> 00:01:18.943 And we yeah, sorry I am in my kitchen.
00:01:18.953 --> 00:01:21.924 I was grabbing a snack real quick and so I couldn't hear
00:01:21.924 --> 00:01:25.157 super clearly, but did you give a very quick overview on what
00:01:25.157 --> 00:01:26.773 entity framework is Slash does?
00:01:26.993 --> 00:01:29.065 Because we have a lot of people in here that don't really write
00:01:29.065 --> 00:01:29.713 back in code at all.
00:01:29.413 --> 00:01:30.543 Actually true.
00:01:30.553 --> 00:01:33.043 True, I I wasn't even thinking about that.
00:01:33.053 --> 00:01:33.913 I apologize.
00:01:34.093 --> 00:01:34.423 OK.
00:01:34.433 --> 00:01:34.703 Yeah.
00:01:34.653 --> 00:01:38.603 So yeah. Yeah.
00:01:34.713 --> 00:01:40.033 So let's start with like an Eli five of entity framework.
00:01:40.553 --> 00:01:45.624 So any framework is called a an OEM or an object relational map,
00:01:45.624 --> 00:01:49.603 or basically to explain it in a really high level.
00:01:49.613 --> 00:01:53.749 It allows us to get stuff from the database without having to
00:01:53.749 --> 00:01:54.683 write raw SQL.
00:01:55.963 --> 00:02:00.033 UM, is there anyone in in here who hasn't used EF at all?
00:02:00.083 --> 00:02:04.055 And I guess I'm probably just picking on, on, on one person
00:02:04.055 --> 00:02:07.895 because I'm, I'm pretty sure Michael has and I know David
00:02:07.895 --> 00:02:10.543 has, but has anyone not used EF at all?
00:02:11.383 --> 00:02:12.853 OK, so you haven't used EF at all.
00:02:15.473 --> 00:02:18.183 So essentially we can do is.
00:02:18.193 --> 00:02:23.603 Do you know what link is Alex LINQ well?
00:02:22.963 --> 00:02:26.282 Umm, isn't that like where it it looks similar to SQL in the
00:02:26.282 --> 00:02:27.643 statements that we write.
00:02:26.823 --> 00:02:30.768 So in C sharp you've used stuff like dot first or default or
00:02:30.768 --> 00:02:31.803 whatever, right?
00:02:32.443 --> 00:02:32.683 Yeah.
00:02:33.543 --> 00:02:34.103 It's OK.
00:02:33.903 --> 00:02:35.023 So yeah.
00:02:34.113 --> 00:02:40.748 So yeah, it's kind of similar in like your, UM, umm sorry, I'm
00:02:40.748 --> 00:02:42.223 brain melting.
00:02:42.533 --> 00:02:46.622 It's kind of similar in JavaScript or TypeScript to your
00:02:46.622 --> 00:02:49.923 methods like dot filter dot sum dot etcetera.
00:02:50.833 --> 00:02:55.123 Those those sort of methods that operate on a array or collection
00:02:55.123 --> 00:02:59.283 of items and they let you sort of filter them down or determine
00:02:59.283 --> 00:03:03.183 conditions about the data set and all that kind of stuff or
00:03:03.183 --> 00:03:05.133 map is another one in C sharp.
00:03:05.143 --> 00:03:09.782 All of those methods live in a a collection called Link, and they
00:03:09.782 --> 00:03:13.929 have slightly different names compared to their JavaScript
00:03:13.929 --> 00:03:14.843 counterparts.
00:03:14.853 --> 00:03:18.379 So instead of filter it's where instead of map it's select, so
00:03:18.379 --> 00:03:21.513 they're kind of more similar to like SQL command names.
00:03:22.663 --> 00:03:23.633 Umm, but they all.
00:03:23.643 --> 00:03:25.913 They're all effectively are are operating the same way.
00:03:27.033 --> 00:03:27.323 Yeah.
00:03:27.333 --> 00:03:30.620 So let me I'll zoom in it over here because I know it's gonna
00:03:30.620 --> 00:03:33.855 be hard to see because I'm on ultrawide, so I apologize, but
00:03:33.855 --> 00:03:35.923 you'll have to put up with it for now.
00:03:35.933 --> 00:03:39.943 But basically, when I talk about Lynch, you could just have like
00:03:39.943 --> 00:03:43.891 let's say you have a bar, some list equals a new list of string
00:03:43.891 --> 00:03:45.063 or whatever, right?
00:03:45.473 --> 00:03:49.709 And then, umm, an example of me asking like, hey, have you used
00:03:49.709 --> 00:03:53.946 link you could say like hey get me the the first element in the
00:03:53.946 --> 00:03:58.050 list, right and that would be like our first element is equal
00:03:58.050 --> 00:04:02.022 to sum list out first and then whatever it's all greyed out
00:04:02.022 --> 00:04:05.729 because essentially like Resharper writer tells me that
00:04:05.729 --> 00:04:07.053 it's not being used.
00:04:07.383 --> 00:04:11.252 Umm, but imagine there's syntax highlighting there, but
00:04:11.252 --> 00:04:15.466 basically what EF allows us to do is say hey, I just want to
00:04:15.466 --> 00:04:19.612 use like LINQ extension methods like filter by ID's and two
00:04:19.612 --> 00:04:23.965 lists and other things to build out an SQL query and then fire
00:04:23.965 --> 00:04:28.110 it off and then I was going to start talking about the Fred
00:04:28.110 --> 00:04:30.943 execution but that's I'll do that later.
00:04:31.393 --> 00:04:33.173 Totally drowned people, so.
00:04:35.463 --> 00:04:38.239 I guess I'll ask this and this will be, I guess, an interesting
00:04:38.239 --> 00:04:40.929 exercise for the front Enders and I hate to pick on you guys,
00:04:40.929 --> 00:04:41.103 but.
00:04:43.633 --> 00:04:47.415 Let's say for example this this one method I have in the middle
00:04:47.415 --> 00:04:48.183 of my screen.
00:04:49.033 --> 00:04:50.993 Ignore the fact that it's supposed to return unpaid
00:04:50.993 --> 00:04:51.333 invoices.
00:04:51.343 --> 00:04:54.684 Let's just say we're we're getting some invoices by ID's
00:04:54.684 --> 00:04:55.153 for now.
00:04:55.163 --> 00:04:59.380 So we'll just say, uh, I'll just copy this because I want to use
00:04:59.380 --> 00:05:03.662 this one later, but get invoices by ID or whatever, we'll call it
00:05:03.662 --> 00:05:07.554 that for now for any of the front Enders because I know the
00:05:07.554 --> 00:05:10.993 back end or should probably know the answer to this.
00:05:11.003 --> 00:05:12.193 And if you don't let me know.
00:05:12.203 --> 00:05:15.353 But is there any way we can improve this query?
00:05:15.363 --> 00:05:18.650 Cause all this is supposed to do is say hey, I wanna get invoices
00:05:18.650 --> 00:05:20.643 with these IDs and I wanna return them.
00:05:20.693 --> 00:05:22.983 Is there anything we could do to any you guys?
00:05:22.993 --> 00:05:26.636 That's obvious to make this Curry better or anything we're
00:05:26.636 --> 00:05:27.933 missing specifically.
00:05:27.373 --> 00:05:28.233 Do you like sword?
00:05:30.683 --> 00:05:32.823 Yeah, I guess you could sort it, but that's not.
00:05:32.833 --> 00:05:35.465 I'm not so much looking for any kind of like kind of say like
00:05:35.465 --> 00:05:37.843 surface level stuff like sorting or anything like that.
00:05:38.913 --> 00:05:41.945 Umm I'm I'm more focused on optimization and in one thing
00:05:41.945 --> 00:05:45.238 you'll notice about when you're going in doing these F queries
00:05:45.238 --> 00:05:48.427 like, especially if you're in front end and you're not super
00:05:48.427 --> 00:05:51.616 umm, I guess comfortable with the and you haven't done a lot
00:05:51.616 --> 00:05:54.700 of work in it, you'll probably notice James leaving a much
00:05:54.700 --> 00:05:58.098 comments being like at this add that add this, add that and even
00:05:58.098 --> 00:06:01.443 if you start here in your back end or there's probably a lot of
00:06:01.443 --> 00:06:04.737 stuff you haven't used in your in your personal you know stuff
00:06:04.737 --> 00:06:07.978 with C sharp like even configure await false or whatever that
00:06:07.978 --> 00:06:11.219 James will ask you to add and he's not just doing it to be me
00:06:11.219 --> 00:06:13.153 and he's doing it for a reason so I.
00:06:12.523 --> 00:06:15.383 I mean you wanna filter by active, right?
00:06:16.383 --> 00:06:16.833 OK.
00:06:17.043 --> 00:06:17.953 And yeah.
00:06:17.963 --> 00:06:19.313 So that's an example.
00:06:19.323 --> 00:06:22.993 So filter by active and what does that do so everyone knows?
00:06:24.423 --> 00:06:30.739 So all only sales invoices that are in play get filtered out by
00:06:30.739 --> 00:06:31.233 this.
00:06:32.833 --> 00:06:36.626 Some invoices that are not active will not be filtered on
00:06:33.133 --> 00:06:34.093 Yep, specifically.
00:06:36.626 --> 00:06:36.953 this.
00:06:36.963 --> 00:06:39.723 So now you have a smaller list that you're filtering by ID.
00:06:40.493 --> 00:06:43.520 Yep, specifically filter by active is the same as adding
00:06:41.683 --> 00:06:41.903 Yeah.
00:06:43.520 --> 00:06:45.803 where active equals one on your SQL query.
00:06:45.813 --> 00:06:49.131 So it's just only returns results that have the active
00:06:47.053 --> 00:06:47.253 Yeah.
00:06:49.131 --> 00:06:51.183 flag set to true in the database.
00:06:51.973 --> 00:06:52.573 Yeah. So.
00:06:52.293 --> 00:06:54.383 Who can tell me why we haven't active flag?
00:06:55.993 --> 00:06:58.403 And so does anyone know why we have an active flag?
00:06:58.413 --> 00:06:59.263 I guess that's that's.
00:06:59.273 --> 00:07:00.623 That was gonna be my next question.
00:07:01.733 --> 00:07:02.703 Soft deletes.
00:07:03.723 --> 00:07:04.143 Yeah.
00:07:04.153 --> 00:07:07.807 So the idea is is, yeah, if we wanna be able to quote unquote
00:07:04.793 --> 00:07:05.593 Ding, Ding, Ding.
00:07:07.807 --> 00:07:11.403 delete stuff without actually deleting it, cause you have to
00:07:11.403 --> 00:07:14.763 remember if we straight up delete records, they're gone.
00:07:14.833 --> 00:07:18.083 Like no one can go back and see what it was or anything.
00:07:18.233 --> 00:07:19.703 And then the other, yeah.
00:07:18.273 --> 00:07:20.496 Yeah, they may live in a database backup, but it ain't
00:07:20.496 --> 00:07:22.033 gonna be fun getting it out of there.
00:07:22.573 --> 00:07:25.723 The other part of it is I think this might be true partially.
00:07:25.733 --> 00:07:27.743 At least there's relationships, right?
00:07:27.753 --> 00:07:31.034 Like you can't delete a record that another record is related
00:07:31.034 --> 00:07:31.563 to, right?
00:07:31.333 --> 00:07:32.953 Umm, that's correct.
00:07:31.573 --> 00:07:32.733 That's like dependent on it.
00:07:33.513 --> 00:07:36.569 So instead of having to cascade a bunch of deletes and
00:07:36.569 --> 00:07:40.015 potentially F stuff up for lack of better words, you can just
00:07:40.015 --> 00:07:43.460 set the active flag defaults and then usually on the back end
00:07:43.460 --> 00:07:47.017 what we should be doing unless we intentionally 100% want to be
00:07:47.017 --> 00:07:50.018 able to get soft deleted records, we're always adding
00:07:50.018 --> 00:07:53.519 that filter by active true flag, which just says hey, anything
00:07:53.519 --> 00:07:56.854 that doesn't have active one or active true anything that's
00:07:56.854 --> 00:07:58.243 false or zero, we're not.
00:07:58.253 --> 00:08:00.323 We don't want that return in the query, so that's a good one.
00:08:02.953 --> 00:08:06.567 Anything else that we should be taking into consideration, given
00:08:06.567 --> 00:08:07.123 the query?
00:08:07.133 --> 00:08:09.863 So remember, all we're doing is returning the list.
00:08:09.873 --> 00:08:11.923 You can assume this is getting returned to an endpoint.
00:08:12.153 --> 00:08:15.527 We're not doing any operations on these invoices before sending
00:08:15.527 --> 00:08:18.531 them back or any mapping or anything where we update the
00:08:17.523 --> 00:08:19.973 Are you are you looking for?
00:08:18.531 --> 00:08:19.533 invoices, is there?
00:08:19.593 --> 00:08:25.306 Are you looking for answers from people that aren't me and James
00:08:23.263 --> 00:08:24.043 I'll I'll.
00:08:24.483 --> 00:08:24.933 Yeah.
00:08:24.943 --> 00:08:26.283 So I'll OK, I'll look.
00:08:25.306 --> 00:08:25.833 or OK?
00:08:26.403 --> 00:08:29.539 Anyone who's not your James, including Backhanders now, is
00:08:29.539 --> 00:08:32.516 there anything I should add to this, given that I'm not
00:08:32.516 --> 00:08:33.473 updating a record?
00:08:33.703 --> 00:08:34.283 How about that?
00:08:33.953 --> 00:08:36.708 Well, you said you said no mapping, but that's what I was
00:08:34.993 --> 00:08:38.403 Yeah, but that we should.
00:08:36.708 --> 00:08:37.183 gonna say.
00:08:37.353 --> 00:08:38.713 You you gotta you.
00:08:38.723 --> 00:08:39.663 You're picking everything.
00:08:39.223 --> 00:08:43.353 Daddy, where has no tracking is what you're looking for.
00:08:39.673 --> 00:08:40.773 You gotta pick a few things.
00:08:42.963 --> 00:08:43.313 Yeah.
00:08:43.323 --> 00:08:44.273 There you go.
00:08:44.163 --> 00:08:45.293 Is that what we're looking for? OK.
00:08:44.323 --> 00:08:45.433 That's what I was kind of looking for.
00:08:45.283 --> 00:08:50.322 OK, so before we get too far down the road, let me explain
00:08:50.103 --> 00:08:50.323 Yep.
00:08:50.322 --> 00:08:52.543 what has no tracking does.
00:08:52.553 --> 00:08:57.046 Just for the people that, that again that don't really use any
00:08:57.046 --> 00:09:01.753 framework as no tracking doesn't take any arguments, so whenever.
00:09:03.353 --> 00:09:07.784 Let me let me take a another step slightly further back to
00:09:07.784 --> 00:09:12.441 start building an analog here online 456, that line that says
00:09:12.441 --> 00:09:17.397 using VAR context blah blah blah all we're doing is we're getting
00:09:17.397 --> 00:09:21.603 a database context for all intents and purposes you can
00:09:21.603 --> 00:09:24.833 imagine that context is just the database.
00:09:25.903 --> 00:09:28.813 Umm, it's obviously it's a little more complicated than
00:09:28.813 --> 00:09:29.073 that.
00:09:29.083 --> 00:09:32.191 If you go down, you know, start getting down into the into the
00:09:32.191 --> 00:09:32.833 depths of it.
00:09:33.103 --> 00:09:35.613 But context is the database.
00:09:36.343 --> 00:09:38.443 It's very close analog of it.
00:09:39.273 --> 00:09:39.783 Umm.
00:09:40.393 --> 00:09:46.143 On the next line there 459 now context Dot sales invoices.
00:09:46.153 --> 00:09:47.983 That's a table in the database.
00:09:48.043 --> 00:09:51.907 This so, umm, so effectively what we're doing right there
00:09:51.907 --> 00:09:55.972 ignoring their return await part context dot sales invoices,
00:09:55.972 --> 00:09:59.903 basically saying I want to read something out of the sales
00:09:59.903 --> 00:10:00.903 invoices table.
00:10:01.673 --> 00:10:06.605 Umm, so that's that's sort of the beginning of that, that
00:10:06.605 --> 00:10:11.963 process there is that context is your window into the database
00:10:11.963 --> 00:10:16.810 and sales invoices is your window into the sales invoice
00:10:16.810 --> 00:10:21.743 table in that database umm, so that's all fine and dandy.
00:10:23.923 --> 00:10:26.843 And what you can do just to make this very simple.
00:10:27.693 --> 00:10:31.163 Uh is if you wanna go like a line above this.
00:10:32.063 --> 00:10:32.283 Yep.
00:10:32.173 --> 00:10:32.703 Uh.
00:10:32.713 --> 00:10:35.712 But like between the context and your query there and add like
00:10:35.712 --> 00:10:38.093 VAR invoice and this is gonna be stupidly simple.
00:10:38.103 --> 00:10:41.991 Just to illustrate the point, like VAR invoice equals context
00:10:41.991 --> 00:10:45.628 dot sales invoices dot first, you don't have to do a deal
00:10:45.628 --> 00:10:47.133 waits or just just I'll.
00:10:46.063 --> 00:10:46.653 Alright then.
00:10:47.223 --> 00:10:48.973 I don't wanna make it too complicated here.
00:10:48.883 --> 00:10:49.123 OK.
00:10:49.683 --> 00:10:50.153 Yeah.
00:10:50.243 --> 00:10:54.078 So all we're doing here, this is just a very stupid thing of get
00:10:54.078 --> 00:10:56.143 me the first invoice in the table.
00:10:56.583 --> 00:11:00.736 That's all it's doing, and you'll see that invoice if you
00:11:00.736 --> 00:11:05.103 mouse over that again and that text is really small, but the
00:11:01.553 --> 00:11:01.823 Toll.
00:11:01.833 --> 00:11:04.743 Small, but yeah, I apologize.
00:11:05.103 --> 00:11:09.471 type, the type of invoice is sales invoice, which is a sales
00:11:09.471 --> 00:11:12.263 invoice record, and a database entity.
00:11:12.773 --> 00:11:17.443 Now any framework does some really cool stuff for us.
00:11:17.453 --> 00:11:20.183 It makes a lot of things very, very easy.
00:11:20.853 --> 00:11:25.793 So for example, Tristan, go ahead and hit enter and do
00:11:25.793 --> 00:11:31.004 invoice dot balance due uh equals 5000 uh and then on the
00:11:31.004 --> 00:11:36.663 next line do context dot save changes or uh save unit of work?
00:11:40.163 --> 00:11:40.773 Yeah.
00:11:40.823 --> 00:11:41.253 OK.
00:11:41.303 --> 00:11:43.033 So again, I'm not.
00:11:43.043 --> 00:11:45.023 I'm not a adding in all of the.
00:11:48.573 --> 00:11:50.413 You don't have to pass context back in, it's it's.
00:11:50.453 --> 00:11:51.263 Yeah, you're good.
00:11:51.673 --> 00:11:54.601 But I'm not adding all the async stuff that we would normally be
00:11:51.963 --> 00:11:52.573 This is like.
00:11:54.601 --> 00:11:56.673 using for this, just to for better CPU usage.
00:11:56.683 --> 00:11:58.283 All that I'm not super concerned about that.
00:11:58.293 --> 00:11:59.643 That's a whole other discussion.
00:11:59.713 --> 00:12:03.433 Just trying to illustrate energy framework itself, the so all
00:12:00.743 --> 00:12:00.883 Yeah.
00:12:03.433 --> 00:12:07.213 we've done here is we've read an invoice out and we've read it
00:12:07.213 --> 00:12:10.813 out in a way that allows us to update this record and save.
00:12:10.963 --> 00:12:14.748 So then on line 459, we set its balance due to 5000 and then we
00:12:14.748 --> 00:12:15.753 save our changes.
00:12:16.113 --> 00:12:19.379 What this would actually do is it would effectively it would
00:12:19.379 --> 00:12:21.253 run some SQL against the database.
00:12:21.263 --> 00:12:26.025 That's something along the lines of like update, invoicing, dot
00:12:26.025 --> 00:12:30.342 sales, invoice set balance due equal 5000 where ID equals
00:12:30.342 --> 00:12:32.723 whatever the invoice ID is. Umm.
00:12:34.823 --> 00:12:38.332 So what effectively though, what that boils down to is we've got
00:12:38.332 --> 00:12:40.653 an invoice here that we're able to update.
00:12:40.743 --> 00:12:42.683 We can change values on this invoice.
00:12:43.693 --> 00:12:47.124 Umm and entity framework automatically tracks the things
00:12:47.124 --> 00:12:50.916 that we change so that when we save it knows what to update in
00:12:50.916 --> 00:12:53.023 the database and how to update it.
00:12:53.343 --> 00:12:54.173 Very cool.
00:12:54.183 --> 00:12:54.703 Very nice.
00:12:54.713 --> 00:12:56.613 We don't have to go and write a bunch of SQL ourselves.
00:12:56.623 --> 00:12:58.433 It just does really cool stuff for us.
00:12:58.963 --> 00:13:04.045 However, Umm, as the as they say, there's no such thing as
00:13:04.045 --> 00:13:04.993 free lunch.
00:13:07.423 --> 00:13:11.120 The cool stuff that entity framework does costs processing
00:13:11.120 --> 00:13:11.433 time.
00:13:12.183 --> 00:13:12.733 Umm.
00:13:12.783 --> 00:13:16.762 So what that boils down to is when you have a record that
00:13:16.762 --> 00:13:21.084 you're able to update and it's able to track all these changes
00:13:21.084 --> 00:13:24.720 and updates for you automatically, there's naturally
00:13:24.720 --> 00:13:29.111 going to be some extra overhead, some extra memory usage, extra
00:13:29.111 --> 00:13:33.021 processing time involved in creating those, and tracking
00:13:33.021 --> 00:13:33.433 those.
00:13:33.443 --> 00:13:35.993 Uh, those records as you read them out?
00:13:36.893 --> 00:13:37.413 Umm.
00:13:37.893 --> 00:13:41.786 And if you don't need to update records, you can opt out of that
00:13:41.786 --> 00:13:43.703 tracking to improve performance.
00:13:44.053 --> 00:13:45.843 And that's what asno tracking does.
00:13:46.453 --> 00:13:49.693 So just making sure we kind of have the whole picture there.
00:13:50.213 --> 00:13:54.538 Umm by default entity framework allows you to update records and
00:13:54.538 --> 00:13:58.530 you can opt out of that to improve performance with the dot
00:13:58.530 --> 00:14:00.193 as node tracking section.
00:14:00.203 --> 00:14:01.363 There online 470.
00:14:02.203 --> 00:14:06.593 Umm, so they call it change tracking.
00:14:07.363 --> 00:14:08.013 That's you.
00:14:08.023 --> 00:14:10.968 You may see references to change tracking in different places if
00:14:10.968 --> 00:14:13.914 you're if you decide to kind of poke around within the framework
00:14:13.914 --> 00:14:14.503 a little bit.
00:14:15.253 --> 00:14:19.440 UM, change tracking refers to entity framework's ability to
00:14:19.440 --> 00:14:23.836 track the updates that you make on records you read out, so it
00:14:23.836 --> 00:14:28.023 can update them automagically for you in the database. Umm.
00:14:28.033 --> 00:14:33.883 So what is the benefit of adding a true to the save unit of work
00:14:33.883 --> 00:14:35.683 online for 65 if we?
00:14:34.873 --> 00:14:35.853 Great question.
00:14:35.913 --> 00:14:39.243 OK, so let's go back to 465 and talk about that.
00:14:39.393 --> 00:14:43.573 So line 465 is going to save changes to the database.
00:14:44.533 --> 00:14:48.597 Umm, So what that effectively means is that before we call
00:14:48.597 --> 00:14:50.663 context dot save unit of work.
00:14:50.753 --> 00:14:54.035 What I'm doing online 463 invoice dot balance due equals
00:14:54.035 --> 00:14:54.323 5000.
00:14:54.473 --> 00:14:55.243 That means nothing.
00:14:55.253 --> 00:14:56.653 I haven't actually done anything yet.
00:14:56.663 --> 00:14:58.063 I haven't saved it to the database.
00:14:58.073 --> 00:15:00.943 I've updated that value as I see it in memory.
00:15:00.953 --> 00:15:05.093 My copy of it is updated, but I haven't given that copy back to
00:15:05.093 --> 00:15:09.362 the database and told it this is what I need to save permanently,
00:15:09.362 --> 00:15:10.333 so that's cool.
00:15:11.143 --> 00:15:14.850 Umm, but uh, something that you can pass into here is you can
00:15:14.850 --> 00:15:18.317 actually add a Boolean to the saved unit of work call and
00:15:18.317 --> 00:15:21.666 you'll see that that that Boolean the the variable name
00:15:21.666 --> 00:15:25.313 there is called change required as again that's really small
00:15:25.313 --> 00:15:28.063 text we can kind of see bool change required.
00:15:29.113 --> 00:15:34.774 Umm, So what that means is, umm, we are telling it and you'll see
00:15:34.774 --> 00:15:35.803 also, sorry.
00:15:35.813 --> 00:15:39.789 One more last thing, save unit of work actually returns a
00:15:39.789 --> 00:15:43.833 Boolean, so if you add like var save result equals yeah or
00:15:43.833 --> 00:15:44.793 success equal.
00:15:44.803 --> 00:15:45.303 That's perfect.
00:15:45.313 --> 00:15:45.983 OK, so.
00:15:47.723 --> 00:15:54.093 If we pass false to save unit of work then uh then whenever the
00:15:54.093 --> 00:15:58.373 save is complete it will just return true.
00:15:58.443 --> 00:16:01.223 It'll return false if some error happened.
00:16:01.233 --> 00:16:03.349 Actually, I think it'll just throw the exception of some kind
00:16:03.349 --> 00:16:03.963 of error happened.
00:16:03.573 --> 00:16:07.883 Yeah, the, the the success false is a misnomer.
00:16:07.893 --> 00:16:11.338 If you didn't pass a true to the same unit of work because any
00:16:11.338 --> 00:16:14.728 failure in those cases would have thrown an exception because
00:16:13.793 --> 00:16:14.493 Yeah. So.
00:16:14.728 --> 00:16:18.009 of how how that it would have checked to verify that it was
00:16:18.009 --> 00:16:19.923 able to save everything correctly.
00:16:20.583 --> 00:16:21.073 Yeah.
00:16:21.153 --> 00:16:25.408 So basically, when you pass false or nothing, since the
00:16:25.408 --> 00:16:29.890 default is false, umm, then you'll only ever get back true
00:16:29.890 --> 00:16:34.753 or it will throw an exception as a result of save unit of work.
00:16:35.003 --> 00:16:39.387 However, if you pass true, what you're telling entity framework
00:16:39.387 --> 00:16:43.429 at that point is that you absolutely expect that something
00:16:43.429 --> 00:16:45.553 will have changed on this safe.
00:16:45.623 --> 00:16:49.215 So for example, if the invoice that we've read out on line 461,
00:16:49.215 --> 00:16:52.583 if the balance due was already 5000 and then we called Save
00:16:52.583 --> 00:16:56.119 Unit of Work and passed in true nothing changed that we didn't
00:16:56.119 --> 00:16:59.487 actually update the balance do because it's already what we
00:16:59.487 --> 00:17:00.273 changed it to.
00:17:00.463 --> 00:17:02.303 So it would return false.
00:17:03.523 --> 00:17:06.647 Umm, so that's sort of thing where it's like if you know that
00:17:06.647 --> 00:17:09.520 you're what you're doing absolutely should be altering a
00:17:09.520 --> 00:17:09.873 record.
00:17:11.533 --> 00:17:13.593 For example, creating new records or that kind of thing?
00:17:14.133 --> 00:17:14.763 Umm.
00:17:14.913 --> 00:17:17.762 Then you can pass true to save unit of work and it'll help you
00:17:17.762 --> 00:17:20.657 validate that those changes did occur the way you expected them
00:17:20.657 --> 00:17:20.793 to.
00:17:20.893 --> 00:17:21.203 You.
00:17:22.373 --> 00:17:24.503 So that's what saved unit of work.
00:17:24.513 --> 00:17:30.343 True does if you if you omit the true or false, it'll default to
00:17:30.343 --> 00:17:35.634 false and again all that means is that you are saving some
00:17:35.634 --> 00:17:41.285 changes and it's OK if nothing got updated because it may have
00:17:41.285 --> 00:17:41.913 been a.
00:17:42.063 --> 00:17:44.905 It may have been a thing where something else already made the
00:17:44.905 --> 00:17:46.033 update or whatever it is.
00:17:46.683 --> 00:17:49.960 But when you pass through, you're telling it that something
00:17:49.960 --> 00:17:51.653 absolutely should have changed.
00:17:51.663 --> 00:17:54.385 There should be some difference that was updated in the
00:17:54.385 --> 00:17:54.823 database.
00:17:58.523 --> 00:18:02.094 So before we go too much further there, that was quite a lot of
00:18:02.094 --> 00:18:03.043 of stuff to dump.
00:18:03.053 --> 00:18:04.433 So does anybody have any questions or?
00:18:05.863 --> 00:18:08.243 Anything that they want more clarification on?
00:18:14.103 --> 00:18:14.543 What would?
00:18:15.853 --> 00:18:19.834 What would be the difference between saving of work and save
00:18:19.834 --> 00:18:21.923 unit of work async in this case?
00:18:21.933 --> 00:18:23.433 Like, how would you know you need async?
00:18:24.283 --> 00:18:26.333 You should always be using async.
00:18:24.823 --> 00:18:25.803 Async resources.
00:18:26.423 --> 00:18:29.923 Yeah, you should always be using async where you can umm.
00:18:30.163 --> 00:18:33.415 So I don't wanna go like super deep into what the the async
00:18:33.415 --> 00:18:36.830 await stuff does in in C sharp, but ultimately what it's doing
00:18:36.830 --> 00:18:40.353 is it's yielding processing time to anything else that needs it.
00:18:40.363 --> 00:18:44.832 While some asynchronous process is running Umm interchange first
00:18:44.832 --> 00:18:46.413 to first or default or.
00:18:46.423 --> 00:18:47.163 Sorry, first async?
00:18:48.383 --> 00:18:48.723 All right.
00:18:48.493 --> 00:18:51.543 Umm yeah, but what that what?
00:18:51.553 --> 00:18:55.799 That kind of means is that in the old days, before I'm before
00:18:55.799 --> 00:18:57.443 async await and C sharp.
00:18:58.053 --> 00:19:01.149 If you had a long running process, umm, I guess you can
00:19:01.149 --> 00:19:04.411 think of it like you've got a certain number of threads in
00:19:04.411 --> 00:19:08.004 your processor and if you wanna imagine those threads as runners
00:19:08.004 --> 00:19:10.603 on a track and they're all in their own lanes.
00:19:11.873 --> 00:19:12.293 Umm.
00:19:13.883 --> 00:19:18.104 In the old days, a long running save was sort of like a hurdle
00:19:18.104 --> 00:19:21.253 in the track that would slow that runner down.
00:19:21.523 --> 00:19:24.258 They'd have to jump over it, go around it, whatever it is, and
00:19:24.258 --> 00:19:25.083 it slows them down.
00:19:25.093 --> 00:19:26.633 And there's nothing they can do about that.
00:19:26.643 --> 00:19:27.473 That thread?
00:19:27.483 --> 00:19:30.584 That runner is just blocked until they get around that
00:19:30.584 --> 00:19:30.923 thing.
00:19:30.933 --> 00:19:36.594 Until that long running process is complete, async await is kind
00:19:36.594 --> 00:19:41.819 of like giving them away to effectively yield that lane and
00:19:41.819 --> 00:19:43.213 move to another.
00:19:43.223 --> 00:19:43.703 Not necessarily.
00:19:43.713 --> 00:19:44.043 Move to.
00:19:44.053 --> 00:19:47.081 It's not a perfect analogy, but effectively it it's it's
00:19:47.081 --> 00:19:50.481 allowing them to say like, OK, this lanes blocked right now, so
00:19:50.481 --> 00:19:53.615 I can't use this one, but anything else that I need to do,
00:19:53.615 --> 00:19:56.962 I can jump to another lane and do that and then I'll come back
00:19:56.962 --> 00:19:57.653 to that lane.
00:19:57.663 --> 00:19:59.973 Once I'm around that block, if that makes sense.
00:20:00.583 --> 00:20:03.951 So it's basically just a way to ensure better utilization of the
00:20:01.403 --> 00:20:01.643 Umm.
00:20:03.951 --> 00:20:07.267 processor and making sure that not everything is blocked all at
00:20:07.267 --> 00:20:07.993 the same time.
00:20:08.693 --> 00:20:09.293 Umm.
00:20:09.973 --> 00:20:13.490 And ultimately, what that boils down to is that anywhere that
00:20:13.490 --> 00:20:16.894 you are already in an async method which you can see online
00:20:16.894 --> 00:20:18.993 452, it says like public async task.
00:20:19.763 --> 00:20:21.243 Umm anything?
00:20:21.253 --> 00:20:24.823 Any method that's returning a task of any kind.
00:20:24.833 --> 00:20:28.601 So task list, task stuff, action, sponse, task anything or
00:20:28.601 --> 00:20:29.623 just task alone.
00:20:29.993 --> 00:20:33.381 That method can be async, and if it isn't already, you can add
00:20:33.381 --> 00:20:36.824 the async word before task and you can await things inside that
00:20:36.824 --> 00:20:37.093 call.
00:20:38.543 --> 00:20:41.952 Now there's a lot of other things I could go into there
00:20:41.952 --> 00:20:43.413 around, like a lighting.
00:20:43.423 --> 00:20:46.433 It waits by just returning task objects directly.
00:20:46.903 --> 00:20:48.213 Not gonna cover that again.
00:20:48.463 --> 00:20:53.657 The the real uh, the real meat and potatoes of async await is a
00:20:53.657 --> 00:20:58.851 an entire training topic in and of itself, so I don't wanna get
00:20:58.851 --> 00:20:59.663 into that.
00:21:00.213 --> 00:21:03.603 But yeah, Tim, actually that's a fantastic, fantastic point.
00:21:02.593 --> 00:21:02.933 Mm-hmm.
00:21:03.693 --> 00:21:07.072 Task is a very similar equivalent to promise on the
00:21:07.072 --> 00:21:10.971 front end, so a task of list of sales invoices is basically
00:21:10.971 --> 00:21:15.064 something it's a promise of a sales invoice array if you wanna
00:21:15.064 --> 00:21:18.638 think about the equivalent on the front end or a close
00:21:18.638 --> 00:21:19.353 equivalent.
00:21:20.293 --> 00:21:23.841 Uh, it's basically saying I don't have the result for this
00:21:23.841 --> 00:21:27.329 yet, but if you wait on me, I will have it eventually and
00:21:27.329 --> 00:21:30.877 async await is basically like waiting on something without
00:21:30.877 --> 00:21:33.403 actually physically blocking a thread so.
00:21:35.993 --> 00:21:39.428 And just to confirm for people in case of front end or gets
00:21:39.428 --> 00:21:42.863 their hands dirty and ends up doing some async stuff in the
00:21:42.863 --> 00:21:45.897 back end, is there ever a instance where we're doing
00:21:45.897 --> 00:21:49.446 anything async where we're not adding a configure await false
00:21:49.053 --> 00:21:51.643 In in NET Framework?
00:21:49.373 --> 00:21:49.563 No.
00:21:49.446 --> 00:21:50.763 at the end or is it OK?
00:21:51.653 --> 00:21:52.713 Absolutely not.
00:21:53.003 --> 00:21:54.573 Umm, the. Yeah.
00:21:53.253 --> 00:21:54.313 OK so.
00:21:54.583 --> 00:21:59.045 Anything you await has to have configure await false because of
00:21:59.045 --> 00:22:01.973 some nitty gritty implementation details.
00:22:01.983 --> 00:22:05.053 I don't fully understand and isn't important.
00:22:05.063 --> 00:22:09.325 Anyway, umm, what it boils down to is if you forget that dot
00:22:09.325 --> 00:22:13.377 configure await false and a perfect storm happens, you'll
00:22:13.377 --> 00:22:15.613 deadlock the app and that sucks.
00:22:13.953 --> 00:22:15.963 At Jr once went into the nitty gritty.
00:22:16.033 --> 00:22:17.203 Yeah, he he wants.
00:22:17.213 --> 00:22:17.983 I remember training.
00:22:17.993 --> 00:22:22.255 Somebody asked that and JG went into the nitty gritty on it once
00:22:19.383 --> 00:22:19.603 Yeah.
00:22:22.255 --> 00:22:25.533 and it was pretty long and etcetera and the yeah.
00:22:23.073 --> 00:22:25.223 It's it's very complex.
00:22:25.233 --> 00:22:28.665 It has something to do with like a very low level implementation
00:22:26.053 --> 00:22:26.213 Yeah.
00:22:28.665 --> 00:22:30.883 detail of ASP .net and the way that they.
00:22:32.073 --> 00:22:34.183 Something something sync context?
00:22:34.193 --> 00:22:34.743 I don't.
00:22:34.813 --> 00:22:35.983 It's whatever, it doesn't matter.
00:22:36.143 --> 00:22:40.234 But all the all it boils down to for for us in our day to day is
00:22:40.234 --> 00:22:43.003 just don't forget to configure await falls.
00:22:43.013 --> 00:22:44.323 So we don't deadlock the app.
00:22:44.963 --> 00:22:46.183 That's, that's all that matters.
00:22:47.483 --> 00:22:50.698 And it and if I recall correctly actually has some performance
00:22:50.698 --> 00:22:53.812 and implications if you don't do that as well, it's actually
00:22:53.812 --> 00:22:56.823 faster to set configure a way to false explicitly as well.
00:22:57.663 --> 00:23:00.303 So another little bonus point there.
00:22:59.033 --> 00:23:02.967 Yeah, the IT as far as the the company of clarity is concerned
00:22:59.133 --> 00:22:59.293 Yeah.
00:23:02.967 --> 00:23:06.964 and any in any developer within clarity do configure away false
00:23:06.964 --> 00:23:08.713 period like don't not do it.
00:23:09.203 --> 00:23:09.403 Yeah.
00:23:12.083 --> 00:23:12.183 Cool.
00:23:12.273 --> 00:23:13.883 So, but great questions.
00:23:13.933 --> 00:23:14.243 Yeah.
00:23:14.253 --> 00:23:17.942 And and for anybody that has looked at back in code and
00:23:17.942 --> 00:23:22.289 wondered what the hell configure weight falls is it's magic fairy
00:23:22.289 --> 00:23:25.583 dust that keeps the app from Deadlocking. That's.
00:23:25.263 --> 00:23:25.733 Yeah, I was.
00:23:25.743 --> 00:23:26.103 I was.
00:23:26.113 --> 00:23:27.643 I was just gonna be like Ed as a rule.
00:23:27.343 --> 00:23:30.903 I don't not use it, yeah.
00:23:27.653 --> 00:23:29.773 Don't use it or don't not use it.
00:23:29.783 --> 00:23:31.163 And I was like, I should probably.
00:23:31.383 --> 00:23:33.893 I was I I should probably ensure that's true.
00:23:34.433 --> 00:23:39.291 To say it, but I always put this at the end unless I accidentally
00:23:34.493 --> 00:23:34.613 Yes.
00:23:39.291 --> 00:23:40.543 forget, but yeah.
00:23:43.833 --> 00:23:44.803 Just one more chance.
00:23:44.213 --> 00:23:44.413 Cool.
00:23:44.813 --> 00:23:47.583 If anyone has any questions or anything or no, are we good?
00:23:48.323 --> 00:23:48.853 Yeah.
00:23:48.923 --> 00:23:53.376 So I think again, unless anybody has any questions and and we
00:23:53.376 --> 00:23:54.813 have plenty of time.
00:23:55.583 --> 00:23:57.193 So don't feel like you're holding anything up.
00:23:57.203 --> 00:23:59.200 If you do have questions, you're like, I don't wanna hold
00:23:59.200 --> 00:23:59.613 anything up.
00:23:59.943 --> 00:24:02.333 We got plenty of time, feel free to ask any questions.
00:24:02.343 --> 00:24:04.923 You have no question is a bad question.
00:24:04.933 --> 00:24:07.753 This is not a, it's a complicated topic.
00:24:07.763 --> 00:24:10.819 And uh, so be great for everybody to have a good idea of
00:24:10.819 --> 00:24:13.553 kind of what it means and and how to work with it.
00:24:13.563 --> 00:24:16.036 So if you do have any questions, now is the time, feel free to
00:24:16.036 --> 00:24:16.193 ask.
00:24:20.733 --> 00:24:22.913 And if not, on we go.
00:24:23.653 --> 00:24:27.304 Umm, so one other thing I wanted to and I think you may be this
00:24:27.304 --> 00:24:30.213 may be what you're starting to try to get at next.
00:24:30.823 --> 00:24:31.133 Umm.
00:24:31.133 --> 00:24:33.763 Umm Tristan, but and.
00:24:33.773 --> 00:24:34.673 And I don't wanna.
00:24:34.843 --> 00:24:36.643 OK, uh, what do you call it?
00:24:37.093 --> 00:24:38.673 I'll I'll tell you where I'll go.
00:24:38.683 --> 00:24:39.603 I was gonna go where?
00:24:39.613 --> 00:24:40.923 And then select and then.
00:24:40.933 --> 00:24:43.933 I was gonna eventually get into some stuff.
00:24:43.943 --> 00:24:46.825 That's probably way over some people's heads, but I was gonna
00:24:46.825 --> 00:24:49.475 get into deferred execution eventually just for the back
00:24:49.033 --> 00:24:49.503 OK.
00:24:49.475 --> 00:24:50.173 end, ours, but.
00:24:50.133 --> 00:24:53.023 You by deferred execution, do you mean like lazy loading or?
00:24:54.493 --> 00:24:58.771 So I mean like if we wanted, yeah query building so like and
00:24:54.913 --> 00:24:56.063 Or query building.
00:24:58.363 --> 00:24:59.323 OK, alright. OK.
00:24:58.771 --> 00:25:03.190 also like for example filter by ID's if we have more than like
00:25:03.190 --> 00:25:07.399 500 records we're trying to get we we would need to do that
00:25:07.399 --> 00:25:09.573 otherwise it'll freak out yeah.
00:25:07.543 --> 00:25:08.673 Ohh yeah, so you would.
00:25:08.683 --> 00:25:08.953 Yeah.
00:25:08.993 --> 00:25:09.793 OK, cool.
00:25:09.863 --> 00:25:15.530 So I wanna go ahead and hit a select first because I think
00:25:15.530 --> 00:25:19.373 that that's a a pretty a pretty useful.
00:25:17.973 --> 00:25:18.173 OK.
00:25:20.203 --> 00:25:21.503 Uh next step.
00:25:23.193 --> 00:25:23.933 So let's.
00:25:28.363 --> 00:25:31.836 Let's go back to the the initial example in that region that we
00:25:31.836 --> 00:25:32.813 have up there 459.
00:25:33.363 --> 00:25:39.378 OK, so looking at line 461, where reading whatever the first
00:25:39.378 --> 00:25:40.463 invoice is.
00:25:41.723 --> 00:25:45.590 Sorry, I'm yeah, we're reading the first invoice out of the
00:25:45.590 --> 00:25:49.393 database, whatever that happens to be doesn't matter what.
00:25:49.403 --> 00:25:55.425 This actually equates to in SQL would be if you wanna write this
00:25:55.425 --> 00:25:57.093 as a comment team.
00:25:57.103 --> 00:26:01.271 OK, this line or this database query from 461 to 464 is
00:26:01.271 --> 00:26:02.313 equivalent to.
00:26:04.043 --> 00:26:06.803 Select top one star.
00:26:08.443 --> 00:26:09.753 Umm. Hang on.
00:26:10.403 --> 00:26:10.833 Hello.
00:26:11.553 --> 00:26:11.913 Yeah.
00:26:11.963 --> 00:26:18.593 Select top one star from invoicing dot sales invoices.
00:26:21.403 --> 00:26:22.753 Or sales invoice I guess.
00:26:23.163 --> 00:26:24.693 I think our table names are singular.
00:26:24.863 --> 00:26:25.283 Yeah.
00:26:25.353 --> 00:26:30.490 So, umm, what that star means is that we're reading everything on
00:26:30.490 --> 00:26:35.238 the sales invoice table out of that data out of the database
00:26:35.238 --> 00:26:36.873 and into this record.
00:26:37.933 --> 00:26:40.863 The top one is obviously just saying the first one basically.
00:26:44.743 --> 00:26:45.813 And yeah, perfect.
00:26:45.863 --> 00:26:47.923 Nice equivalent.
00:26:48.573 --> 00:26:51.213 Well, yeah.
00:26:50.783 --> 00:26:55.108 So yeah, the the query there for 61 through 463 is basically
00:26:55.108 --> 00:26:59.576 equivalent to what is typed in right there on the right, which
00:26:59.576 --> 00:27:00.143 is cool.
00:27:00.343 --> 00:27:02.503 It loads every single thing about the invoice.
00:27:03.483 --> 00:27:06.073 Umm, that's all fine and dandy.
00:27:06.623 --> 00:27:11.069 However, when you are working with the database, every
00:27:11.069 --> 00:27:15.757 additional column that you read from is more memory, more
00:27:15.757 --> 00:27:20.607 processing time, more database work that has to be done, et
00:27:20.607 --> 00:27:21.173 cetera.
00:27:21.503 --> 00:27:25.623 So let's say that the only thing we care about on this invoice.
00:27:25.683 --> 00:27:27.763 Maybe we're not doing this invoice balance update.
00:27:27.773 --> 00:27:32.689 We were talking about and maybe we just want to do some special
00:27:32.689 --> 00:27:37.145 logic on this invoice if it's balanced due is beyond some
00:27:37.145 --> 00:27:37.913 threshold.
00:27:38.593 --> 00:27:42.973 Umm so then really the only thing we need to know at that
00:27:42.973 --> 00:27:45.163 point is the balance due umm.
00:27:45.473 --> 00:27:49.307 So if we were querying for that in the database, we would just
00:27:49.307 --> 00:27:52.716 say select top one balance due from invoicing dot sales
00:27:52.716 --> 00:27:53.203 invoice.
00:27:55.393 --> 00:27:58.034 And the way that we do that in our E.
00:28:00.563 --> 00:28:04.863 C Sharp code is with the the link method select.
00:28:06.273 --> 00:28:07.993 So select uh.
00:28:08.333 --> 00:28:11.650 The technical term for it is projection, but what we're doing
00:28:11.650 --> 00:28:15.128 is we're just we're saying that we want to grab or select just a
00:28:15.128 --> 00:28:16.733 few specific things from this.
00:28:17.583 --> 00:28:20.823 Umm, so it it already autofilled what we need there.
00:28:20.993 --> 00:28:22.773 So if you just X dot balance due.
00:28:24.493 --> 00:28:25.083 Umm.
00:28:26.083 --> 00:28:32.169 Then now the invoice property there is a decimal, a number, C
00:28:32.169 --> 00:28:33.543 sharp for the.
00:28:33.553 --> 00:28:35.403 For those of you that work primarily in TypeScript or.
00:28:36.713 --> 00:28:38.803 Uh or or JavaScript?
00:28:39.613 --> 00:28:44.176 C Sharp has multiple different numerical types and in in
00:28:44.176 --> 00:28:48.819 JavaScript it's basically all just number, but in C sharp
00:28:48.819 --> 00:28:53.142 we've got integers, longs, doubles, floats, decimals,
00:28:53.142 --> 00:28:53.863 etcetera.
00:28:53.933 --> 00:28:54.953 They all do different things.
00:28:57.483 --> 00:29:00.745 Again, not really too big of a deal to get into that too much,
00:29:00.745 --> 00:29:04.059 just you can kind of imagine it as integers and lungs are whole
00:29:04.059 --> 00:29:04.473 numbers.
00:29:05.413 --> 00:29:10.543 Uh doubles and floats are non whole numbers and decimals are
00:29:10.543 --> 00:29:15.168 non whole numbers that are primarily used for currency
00:29:15.168 --> 00:29:18.953 because they are, uh, lossless, if you will.
00:29:19.323 --> 00:29:22.432 And that all goes into how floating point numbers work with
00:29:22.432 --> 00:29:23.313 double and float.
00:29:23.323 --> 00:29:25.733 But I'm not, again, not gonna go too deep into that.
00:29:25.923 --> 00:29:29.453 So I decimal is a currency amount umm.
00:29:30.903 --> 00:29:34.236 And so we've just read the balance due on the 1st invoice
00:29:34.236 --> 00:29:36.363 out of the database with that query.
00:29:37.023 --> 00:29:41.558 Umm this query will run a good bit faster than it would if we
00:29:41.558 --> 00:29:44.923 just commented out that select line line 462.
00:29:45.593 --> 00:29:49.792 Umm, the reason for that is because we're reading whenever
00:29:49.792 --> 00:29:53.992 this SQL query runs, we're actually only reading one thing
00:29:53.992 --> 00:29:58.547 out of the database, where it's just select top one balance due
00:29:58.547 --> 00:29:58.903 like.
00:30:00.643 --> 00:30:02.763 Tristan wrote it on there on Line 460.
00:30:02.943 --> 00:30:06.585 It goes and gets exactly what it needs to do what it's going to
00:30:06.585 --> 00:30:07.723 do and nothing else.
00:30:08.063 --> 00:30:12.012 Very, very specific, very fast, very targeted, et cetera, much
00:30:12.012 --> 00:30:12.953 more efficient.
00:30:13.883 --> 00:30:14.453 Umm.
00:30:14.663 --> 00:30:17.209 Now, obviously, generally speaking, you're reading one
00:30:17.209 --> 00:30:18.413 property or like 1 record.
00:30:18.683 --> 00:30:21.581 The difference is gonna be crazy, but this really comes in
00:30:21.581 --> 00:30:24.626 when you're reading a lot of records in bulk and you're doing
00:30:24.626 --> 00:30:27.623 a lot of work on things, reading things out of the database.
00:30:27.633 --> 00:30:32.239 Everything all at once is not particularly fast, and so the
00:30:32.239 --> 00:30:37.151 more you can do to sort of get in the habit of optimizing these
00:30:37.151 --> 00:30:41.143 queries by just grabbing what you need, the better.
00:30:41.193 --> 00:30:43.585 Generally speaking, the better your overall performance will
00:30:43.585 --> 00:30:43.703 be.
00:30:44.963 --> 00:30:51.119 So now what would let me let me start asking questions from
00:30:51.119 --> 00:30:57.788 people who I think do know stuff but may not know they know some
00:30:57.788 --> 00:31:00.353 stuff, but not all stuff.
00:31:01.163 --> 00:31:04.734 So this one's going for like David and Michael, I know you
00:31:04.734 --> 00:31:08.547 guys have done some stuff with entity framework, but you might
00:31:08.547 --> 00:31:11.453 you might or might not know the answer to this.
00:31:11.463 --> 00:31:12.943 Next question, I'm curious.
00:31:12.953 --> 00:31:17.143 I don't wanna quiz either one of you to and so on.
00:31:17.153 --> 00:31:21.723 Line 473 we're reading one property out balance due.
00:31:22.443 --> 00:31:26.469 Uh, but what if I need to know like balance due and maybe
00:31:26.469 --> 00:31:28.343 account ID on this invoice?
00:31:29.823 --> 00:31:31.693 How how would I do that?
00:31:32.083 --> 00:31:33.083 Because I can't.
00:31:33.703 --> 00:31:37.203 You know I can't do like comma X arrow X dot, whatever.
00:31:37.213 --> 00:31:37.923 That doesn't work.
00:31:37.933 --> 00:31:42.670 You can only pass one thing into this, so how would I read two
00:31:42.670 --> 00:31:45.453 different properties out online 473?
00:31:48.293 --> 00:31:50.753 I'd use the new new anonymous object.
00:31:52.823 --> 00:31:53.493 Ice.
00:31:53.603 --> 00:31:54.953 That is correct.
00:31:55.063 --> 00:32:01.317 So again, it would be it would be cool to to go into anonymous
00:32:01.317 --> 00:32:07.471 objects and and you know the whole C sharp type uh system and
00:32:07.471 --> 00:32:08.563 everything.
00:32:08.613 --> 00:32:13.323 It's very cool, but a whole topic into into itself.
00:32:14.033 --> 00:32:16.103 But what this thing means?
00:32:16.613 --> 00:32:19.641 The so this one's reading the one you're gonna make another
00:32:19.641 --> 00:32:19.843 one.
00:32:19.853 --> 00:32:20.103 Nice thing.
00:32:20.273 --> 00:32:20.343 You.
00:32:20.623 --> 00:32:23.433 Yeah, I totally like, realizes like I already did that once.
00:32:23.443 --> 00:32:26.223 I don't know why I'm making my life harder, but yeah.
00:32:25.293 --> 00:32:25.523 Yeah.
00:32:25.533 --> 00:32:25.633 Yeah.
00:32:27.253 --> 00:32:31.260 So like David said, if you need to read multiple things out, you
00:32:31.260 --> 00:32:31.753 do this.
00:32:31.903 --> 00:32:35.511 It's called an anonymous object where it's just the word new
00:32:35.511 --> 00:32:36.753 followed by brackets.
00:32:37.083 --> 00:32:40.732 This is equivalent in JavaScript to just making an object by
00:32:40.732 --> 00:32:44.203 doing the braces, it's or I should say in TypeScript it's
00:32:44.203 --> 00:32:47.673 the same as doing that without assigning a specific type.
00:32:47.723 --> 00:32:49.833 You can have anything in that object.
00:32:49.843 --> 00:32:52.650 It doesn't conform to any specific interface or anything
00:32:52.650 --> 00:32:53.143 like that.
00:32:53.823 --> 00:32:58.390 Umm, these work similarly, so the what we're doing here now is
00:32:58.390 --> 00:33:02.957 we're telling it that we want to select ID and balance due and
00:33:02.957 --> 00:33:07.596 you can kind of ignore the new part and all that that's sort of
00:33:07.596 --> 00:33:11.293 just implementation detail on how you write these.
00:33:11.703 --> 00:33:14.938 But ultimately, what it boils down to is anything inside that
00:33:14.938 --> 00:33:18.173 object, that new object that we created online for 81 will be
00:33:18.173 --> 00:33:20.313 part of what gets returned on the query.
00:33:20.323 --> 00:33:24.797 So ID and balance due and now on the following line after that
00:33:24.797 --> 00:33:25.223 query.
00:33:25.603 --> 00:33:29.583 So after the configure weight falls, we have access to a non
00:33:29.583 --> 00:33:33.303 object and we can read its ID and its balance due being.
00:33:33.313 --> 00:33:33.793 See that?
00:33:33.833 --> 00:33:36.053 Uh, where's the balance due?
00:33:36.183 --> 00:33:36.783 Ohh, there it is.
00:33:37.263 --> 00:33:37.553 Yeah.
00:33:37.563 --> 00:33:41.303 So we can get it balance due we can get it ID and that's great.
00:33:42.773 --> 00:33:46.093 So couple of things to call out here.
00:33:46.523 --> 00:33:51.743 Number one, whenever you do these projections.
00:33:51.933 --> 00:33:56.053 So for example, online 473 and online 481.
00:33:57.693 --> 00:34:02.503 Umm, these two are implicitly as no tracking.
00:34:02.913 --> 00:34:05.741 So we talked about as no tracking earlier that opts out
00:34:05.741 --> 00:34:07.963 of the ability to update a database record.
00:34:09.003 --> 00:34:09.493 Umm.
00:34:11.133 --> 00:34:16.500 Whenever you project to an anonymous object or to just a
00:34:16.500 --> 00:34:21.772 specific property, uh, the ability to update the record
00:34:21.772 --> 00:34:24.503 based on that result is gone.
00:34:24.583 --> 00:34:25.333 You can't.
00:34:26.363 --> 00:34:29.083 You can't update properties on those anymore.
00:34:32.653 --> 00:34:34.713 Umm yeah.
00:34:37.463 --> 00:34:37.913 Nice.
00:34:37.923 --> 00:34:38.233 OK.
00:34:38.283 --> 00:34:41.606 So then if we go down and we were to do, uh, a little bit
00:34:41.606 --> 00:34:45.044 lower and if we were to do like Anon object dot balance due
00:34:45.044 --> 00:34:48.253 equals 5000 and try to save and nothing's gonna happen.
00:34:48.973 --> 00:34:51.083 Umm, we can't.
00:34:51.133 --> 00:34:53.043 We can't change anything about this.
00:34:53.153 --> 00:34:55.695 In fact, I think it even tells you that that's a read only
00:34:55.695 --> 00:34:56.083 property.
00:34:56.173 --> 00:34:58.843 Possibly I think that might be why there's an error there.
00:35:00.723 --> 00:35:01.933 This is immutable, yeah.
00:35:02.293 --> 00:35:02.803 Yeah.
00:35:02.893 --> 00:35:03.283 Yeah.
00:35:03.293 --> 00:35:06.380 So that's cool and even kind of enforces that, but ultimately
00:35:06.380 --> 00:35:07.923 that's kind of what that means.
00:35:08.263 --> 00:35:09.903 And you could do the same.
00:35:09.913 --> 00:35:13.637 You could show the same thing up there on line 477 if you were to
00:35:13.637 --> 00:35:17.079 try to do like balance due on 1st invoice plus equals 100 or
00:35:17.079 --> 00:35:17.643 something.
00:35:20.423 --> 00:35:21.493 You can't save that.
00:35:22.143 --> 00:35:25.068 If you were to do context dot save changes or context save
00:35:25.068 --> 00:35:26.853 unit of work, nothing would happen.
00:35:26.943 --> 00:35:29.877 You wouldn't actually increase anything because you didn't read
00:35:29.877 --> 00:35:30.703 a database record.
00:35:30.713 --> 00:35:34.393 To update you read a number from the database.
00:35:34.403 --> 00:35:35.813 Any old number doesn't matter.
00:35:35.823 --> 00:35:36.493 It doesn't care.
00:35:36.503 --> 00:35:38.463 It doesn't know so.
00:35:40.553 --> 00:35:43.551 That's just a an important thing to note is that when you do
00:35:43.551 --> 00:35:46.599 these these projections like this, you kind of break the link
00:35:46.599 --> 00:35:46.943 if you.
00:35:46.953 --> 00:35:48.872 If you want to think about it that way, where you can't go
00:35:48.872 --> 00:35:49.653 back and update records.
00:35:49.663 --> 00:35:53.877 So when you're doing, when you're doing updates outside of
00:35:53.877 --> 00:35:58.163 some low level stuff that we don't need to get into because
00:35:58.163 --> 00:36:01.163 we're not doing a massive deep dive here.
00:36:01.743 --> 00:36:05.562 Umm, the only way to update records is to read a full record
00:36:05.562 --> 00:36:05.813 out.
00:36:06.273 --> 00:36:12.623 Umm, so uh, that's just a a useful a useful note here.
00:36:15.013 --> 00:36:19.275 The other thing is that the anonymous object that we write
00:36:19.275 --> 00:36:23.827 out online for 84, if you mouse over a non object there online
00:36:23.827 --> 00:36:26.283 484 it will tell you the type is.
00:36:27.043 --> 00:36:28.513 Uh oh, that's cool.
00:36:28.723 --> 00:36:29.313 Uh.
00:36:29.623 --> 00:36:33.277 In in Visual Studio it actually just doesn't give you any type
00:36:29.743 --> 00:36:29.943 Yeah.
00:36:33.277 --> 00:36:33.973 information.
00:36:34.123 --> 00:36:40.623 It just gives you the types name is apostrophe, a, umm, uh.
00:36:40.633 --> 00:36:45.178 So looks like Resharper writer does some actually cool stuff,
00:36:45.178 --> 00:36:49.283 but ultimately what that means is that the type doesn't
00:36:49.283 --> 00:36:50.383 actually exist.
00:36:50.693 --> 00:36:54.343 It's not a real it's not a sales invoice anymore, it's own.
00:36:55.013 --> 00:36:57.883 Uh, it's own anonymous type.
00:36:59.333 --> 00:37:02.523 Anonymous types cannot be returned as a result of a method
00:37:02.523 --> 00:37:05.606 outside of returning just generic objects, in which case
00:37:05.606 --> 00:37:09.013 they're useless to the to the caller anyway, so don't do that.
00:37:11.883 --> 00:37:14.213 Uh so?
00:37:14.293 --> 00:37:19.075 But what that ultimately means is that you can't do stuff you
00:37:19.075 --> 00:37:23.934 would normally do with a sales invoice using the result of the
00:37:23.934 --> 00:37:25.323 query on line 483.
00:37:25.933 --> 00:37:28.783 UM, because it's not a sales invoice.
00:37:28.793 --> 00:37:30.753 It doesn't function like a sales invoice.
00:37:30.853 --> 00:37:36.246 It's sort of like a a A zoomed in screenshot of a couple of
00:37:36.246 --> 00:37:38.583 pieces of a sales invoice.
00:37:38.593 --> 00:37:41.766 If you want to think about it like that, and we know what
00:37:41.766 --> 00:37:45.213 those pieces do, we know what they mean cause we ask for them.
00:37:45.223 --> 00:37:48.352 We're and we ask for them because they do what we need
00:37:48.352 --> 00:37:51.652 them to do, but we can't use them to do other things that
00:37:51.652 --> 00:37:52.733 invoices can do so.
00:37:54.803 --> 00:37:57.053 Just a couple of important call outs there.
00:37:57.103 --> 00:38:01.363 Uh, in terms of uh, select statements and projections?
00:38:02.253 --> 00:38:05.163 Umm so for remove on to.
00:38:04.063 --> 00:38:08.206 Easiest way, what's the easiest way to just return those two
00:38:05.283 --> 00:38:05.913 Ohh sorry, go ahead.
00:38:08.206 --> 00:38:08.953 properties?
00:38:09.063 --> 00:38:11.033 You know in your your end point you got an endpoint.
00:38:11.043 --> 00:38:16.078 I want list of all of just the IDs and just the balance dues
00:38:16.078 --> 00:38:20.453 for a list of those objects for sales invoices list.
00:38:16.683 --> 00:38:17.163 Umm.
00:38:20.463 --> 00:38:21.963 Hectically OK.
00:38:20.463 --> 00:38:24.393 The quickest way, as I know you can't do it.
00:38:23.283 --> 00:38:27.879 Technically, the the quickest way, the quickest way is to just
00:38:24.403 --> 00:38:27.133 You can't just cast an anonymous object, yeah.
00:38:24.703 --> 00:38:25.533 I do a dictionary.
00:38:27.879 --> 00:38:32.475 return a list of object and the front end can do what it wants
00:38:32.475 --> 00:38:32.913 to do.
00:38:33.363 --> 00:38:36.669 The technically correct way would be to make some kind of
00:38:36.669 --> 00:38:40.090 object, some kind of DTO that's like invoice ID and invoice
00:38:40.090 --> 00:38:43.853 balance, do whatever and and map them onto that and return a list
00:38:43.853 --> 00:38:44.993 of that strong type.
00:38:45.003 --> 00:38:49.333 So as the front end has type uh TypeScript.
00:38:47.593 --> 00:38:50.333 Can you select a new object like, not just a new anonymous?
00:38:50.343 --> 00:38:53.893 You know new my ID balance to object.
00:38:52.033 --> 00:38:57.483 In EF in in EF6, unfortunately no.
00:38:57.693 --> 00:38:58.343 Yeah, out.
00:38:58.483 --> 00:38:59.893 Yeah, it has to be.
00:38:58.953 --> 00:39:00.813 There's that all sucks.
00:38:59.943 --> 00:39:01.483 It has to be. Yeah.
00:39:01.493 --> 00:39:06.543 You either select a property and anonymous object or you can do
00:39:06.543 --> 00:39:08.753 like new sales invoice. Umm.
00:39:07.283 --> 00:39:09.973 I guess you could just knew it up after you've selected those.
00:39:10.163 --> 00:39:10.913 Yeah. Map.
00:39:10.923 --> 00:39:15.043 Map what you map your anonymous object into a new list of.
00:39:15.163 --> 00:39:16.503 You know other objects?
00:39:15.823 --> 00:39:17.313 That's that's what you'd have to do.
00:39:17.103 --> 00:39:19.113 I guess that's why we do that in dump reader.
00:39:17.323 --> 00:39:18.473 Yeah, IN.
00:39:19.573 --> 00:39:20.103 Yeah.
00:39:19.603 --> 00:39:21.073 I've always wondered why we did that.
00:39:20.153 --> 00:39:21.913 In the yeah.
00:39:21.923 --> 00:39:27.262 In entity framework core, yeah, and entity framework core you
00:39:22.073 --> 00:39:22.213 Yes.
00:39:23.083 --> 00:39:23.513 Yeah, OK.
00:39:27.262 --> 00:39:29.243 can select to any type.
00:39:30.013 --> 00:39:30.253 Well.
00:39:30.063 --> 00:39:34.156 Umm, it's very cool and I am using that in the custom Mapper
00:39:32.083 --> 00:39:32.293 Yeah.
00:39:34.156 --> 00:39:35.833 that I wrote for Phoenix.
00:39:35.443 --> 00:39:39.959 I only ask specifically because I tried to do that exactly right
00:39:35.843 --> 00:39:39.083 But yeah.
00:39:39.959 --> 00:39:44.059 there like 493 and it was was slightly miffed today that I
00:39:43.333 --> 00:39:46.109 Yeah, uh TMK the reason you got a little warning there is
00:39:44.059 --> 00:39:44.893 couldn't so.
00:39:45.193 --> 00:39:45.403 Uh.
00:39:46.109 --> 00:39:49.076 because you're doing a first async, so you're not returning a
00:39:49.076 --> 00:39:49.603 collection.
00:39:49.613 --> 00:39:51.963 So what you wanna do is don't do it too list.
00:39:50.123 --> 00:39:50.803 Alright, yeah.
00:39:52.253 --> 00:39:57.765 Do a take 1.2 list async before your configure with false and
00:39:57.765 --> 00:39:58.743 everything.
00:39:58.843 --> 00:39:59.233 OK.
00:39:59.193 --> 00:40:02.586 So instead of returning a first, you're going to do a, take one,
00:39:59.243 --> 00:40:00.163 So you're sounding like.
00:40:00.233 --> 00:40:00.413 Yeah.
00:40:02.586 --> 00:40:03.943 and then a two list async.
00:40:04.003 --> 00:40:06.483 So then you're returning a list that has one thing in it, and
00:40:06.483 --> 00:40:08.803 then you remove your take right there and you'll be good.
00:40:07.733 --> 00:40:08.013 OK.
00:40:11.143 --> 00:40:11.623 There we go.
00:40:11.163 --> 00:40:11.373 Yeah.
00:40:11.383 --> 00:40:14.271 And then you just like return to like first or default or
00:40:14.271 --> 00:40:16.413 whatever or just first I guess at the end.
00:40:14.643 --> 00:40:15.163 Yeah, I'm like.
00:40:17.463 --> 00:40:19.273 So this is a little bit goofy.
00:40:20.293 --> 00:40:23.601 It's not something you're gonna run into a lot, especially if
00:40:23.601 --> 00:40:26.856 you're just, like, writing a really quick query where you're
00:40:26.856 --> 00:40:27.443 projecting.
00:40:29.513 --> 00:40:31.283 We are projecting like across things.
00:40:31.353 --> 00:40:32.043 Uh, like this?
00:40:32.053 --> 00:40:35.290 From from a table to an anonymous type to a model or
00:40:35.290 --> 00:40:39.078 that kind of thing and kind of kind of rare that you're gonna
00:40:39.078 --> 00:40:39.933 run into this.
00:40:40.123 --> 00:40:42.453 But it does happen. Uh.
00:40:44.523 --> 00:40:49.536 And ultimately, the reason for this is if you were to add new
00:40:49.536 --> 00:40:52.123 sales invoice model on line 486.
00:40:53.133 --> 00:40:53.853 Umm.
00:40:54.253 --> 00:40:59.175 So inside the first select, if you were to try to map that to a
00:40:55.483 --> 00:40:55.713 Yes.
00:40:59.175 --> 00:41:03.713 new sales invoice model up there like on 486 on 486, yeah.
00:41:01.433 --> 00:41:02.413 Sorry, what did you want to do?
00:41:02.423 --> 00:41:03.923 Oh, oh, you're saying?
00:41:03.723 --> 00:41:07.232 Like if you were to, yeah, if you were to go up here and add
00:41:03.993 --> 00:41:04.633 Ohh yeah yeah.
00:41:07.232 --> 00:41:10.453 sales invoice model then this is gonna build just fine.
00:41:10.463 --> 00:41:12.483 Everything's gonna act like it's gonna work.
00:41:13.313 --> 00:41:14.803 Uh, everything just lights up.
00:41:14.813 --> 00:41:16.073 Red, as they say that that's funny.
00:41:16.593 --> 00:41:17.853 Umm, but.
00:41:17.953 --> 00:41:18.243 Uh.
00:41:18.253 --> 00:41:21.733 So it'll still let me do it, but well, let me do it and.
00:41:21.113 --> 00:41:24.770 It part hold on the reason it's complaining is because you since
00:41:24.770 --> 00:41:28.259 you specified a model, it wants you to have the properties on
00:41:28.259 --> 00:41:30.003 there as a property assignment.
00:41:30.253 --> 00:41:33.013 You can't just select the the elements, so you can put ID
00:41:30.603 --> 00:41:30.963 Ohh.
00:41:33.013 --> 00:41:34.393 equal and balance it 2 equal.
00:41:33.213 --> 00:41:34.493 Oh, yeah, you're right.
00:41:34.833 --> 00:41:39.308 Yeah, so this will compile and it'll look like it's gonna work
00:41:34.993 --> 00:41:35.283 Yeah.
00:41:35.293 --> 00:41:35.993 There we go. Sorry.
00:41:39.308 --> 00:41:39.663 fine.
00:41:39.933 --> 00:41:41.273 And that's all great.
00:41:41.413 --> 00:41:44.512 But when this actually runs and this query tries to execute,
00:41:44.512 --> 00:41:47.459 entity framework is gonna say I have no idea what a sales
00:41:47.459 --> 00:41:48.323 invoice model is.
00:41:48.373 --> 00:41:50.353 I don't know what an A model is.
00:41:50.363 --> 00:41:51.283 I know what an entity is.
00:41:51.293 --> 00:41:54.043 I don't know what a model is, so I can't execute this query.
00:41:54.993 --> 00:41:58.500 Umm, so that's a really important thing to know is that
00:41:58.500 --> 00:42:02.132 as nice as it would be to be able to do it this way, EF 6
00:42:02.132 --> 00:42:03.573 does not work this way.
00:42:03.893 --> 00:42:07.382 Umm like I said, EF core does, but we're not on EF core yet, so
00:42:07.382 --> 00:42:08.473 that doesn't matter.
00:42:10.793 --> 00:42:13.954 So all you at this point what that kind of boils down to is
00:42:13.954 --> 00:42:17.273 that you just have to, you gotta have a little bit of, yeah, a
00:42:15.393 --> 00:42:16.713 Do the goofy thing we did.
00:42:17.273 --> 00:42:20.381 little bit of extra code, unfortunately, just the the life
00:42:20.381 --> 00:42:20.803 we lead.
00:42:22.553 --> 00:42:24.533 So umm.
00:42:24.153 --> 00:42:27.363 Yeah, you you got a cast into sales invoice model.
00:42:27.373 --> 00:42:30.303 You have to do this goofy stuff, but umm.
00:42:29.433 --> 00:42:29.783 Yeah.
00:42:29.793 --> 00:42:33.681 So you select tune Anonymous, take the one that you need and
00:42:33.681 --> 00:42:37.759 then return a list with two list async and then projection into
00:42:36.263 --> 00:42:38.533 And then this this is no longer anonymous.
00:42:37.759 --> 00:42:38.843 the actual model.
00:42:38.543 --> 00:42:41.678 This is an actual innumerable of whatever, and you just do to
00:42:39.953 --> 00:42:40.093 Yeah.
00:42:41.678 --> 00:42:44.863 list async or whatever Verts or sorry two list but either way.
00:42:42.203 --> 00:42:42.773 Yeah.
00:42:42.863 --> 00:42:45.183 OK, OK.
00:42:45.193 --> 00:42:49.084 So stopping here for just a moment because there's a pretty
00:42:49.084 --> 00:42:53.105 important thing that I wanna talk about that is very relevant
00:42:53.105 --> 00:42:57.062 to what we just discussed and but I wanna make sure before I
00:42:57.062 --> 00:42:58.813 move on to this is anybody.
00:42:59.163 --> 00:42:59.953 Did we lose anybody?
00:43:00.653 --> 00:43:04.026 Uh, is everybody's keeping up understanding everything's good
00:43:04.026 --> 00:43:04.733 can actually.
00:43:06.493 --> 00:43:08.143 Can actually can I get everyone to?
00:43:06.513 --> 00:43:07.533 Yeah, just to confirm.
00:43:08.213 --> 00:43:08.653 Yeah, go ahead.
00:43:09.053 --> 00:43:11.043 Ah, doing it.
00:43:11.053 --> 00:43:11.563 How?
00:43:11.573 --> 00:43:12.513 He just did.
00:43:12.523 --> 00:43:16.003 Before he removed that extra slight to making it to a new
00:43:14.783 --> 00:43:14.963 Yeah.
00:43:16.003 --> 00:43:19.363 model, that's still pretty darn performance compared to
00:43:19.363 --> 00:43:20.923 selecting the whole model.
00:43:20.563 --> 00:43:21.053 Correct.
00:43:21.463 --> 00:43:25.261 Yes, this is, yeah, this is just if you need to return like a
00:43:21.493 --> 00:43:21.713 Yes.
00:43:21.893 --> 00:43:22.813 So this is.
00:43:25.261 --> 00:43:29.060 type like sales invoice model instead of like one property or
00:43:29.060 --> 00:43:29.673 something.
00:43:29.903 --> 00:43:31.233 This is how you would do this.
00:43:31.323 --> 00:43:34.329 It's it's still performant because the the bulk of your
00:43:34.329 --> 00:43:37.334 performance gain is from the select online for 86 where
00:43:37.334 --> 00:43:40.769 you're grabbing just the things you need rather than everything
00:43:40.769 --> 00:43:41.843 in the kitchen sink.
00:43:43.423 --> 00:43:46.533 So, but so that's a fantastic question.
00:43:46.663 --> 00:43:50.333 You're not losing performance on this because the select, and
00:43:50.333 --> 00:43:54.063 that's a kind of feel fuels into the next thing I'm gonna talk
00:43:54.063 --> 00:43:57.793 about, which is umm, basically how does this help performance?
00:43:56.793 --> 00:43:57.123 He.
00:43:57.803 --> 00:43:59.393 Where is the performance?
00:43:59.503 --> 00:44:00.353 What is?
00:44:01.263 --> 00:44:03.523 But I wanted to make sure real quick that everyone's good. So.
00:44:02.743 --> 00:44:03.263 How are you?
00:44:04.123 --> 00:44:04.843 Not bless you.
00:44:04.893 --> 00:44:09.073 And he can now save this model, right?
00:44:09.523 --> 00:44:12.533 It's now. OK.
00:44:10.923 --> 00:44:11.443 No.
00:44:12.173 --> 00:44:15.033 Well, so there is a difference between.
00:44:13.803 --> 00:44:14.193 Yeah.
00:44:14.103 --> 00:44:14.453 OK.
00:44:14.203 --> 00:44:17.793 So the model technically technically yes you could.
00:44:14.463 --> 00:44:16.083 So that that's still can't be updated.
00:44:17.853 --> 00:44:22.024 You could call like workflows dot sales invoices dot update
00:44:22.024 --> 00:44:25.987 async but because the only two properties we set on that
00:44:25.987 --> 00:44:30.437 invoice were ID and balance due everything else on that invoice
00:44:30.013 --> 00:44:30.853 I see. OK.
00:44:30.437 --> 00:44:32.453 would get mold out umm so uh.
00:44:33.773 --> 00:44:38.143 So yeah, just basically without everything being populated.
00:44:38.643 --> 00:44:41.236 It's tough to specifically update things and again, there
00:44:41.236 --> 00:44:42.533 are ways to work around that.
00:44:43.323 --> 00:44:43.953 Umm.
00:44:45.573 --> 00:44:48.783 So, uh yeah.
00:44:48.793 --> 00:44:50.957 Anyway, yeah, so there's ways to work around that with, like
00:44:50.957 --> 00:44:53.300 really advanced level stuff that we're not gonna talk about today
00:44:53.300 --> 00:44:55.003 unless we have a little bit of time at the end.
00:44:55.603 --> 00:44:56.163 Umm.
00:44:56.583 --> 00:44:59.964 But suffice to say, without reading everything out, it's
00:44:59.964 --> 00:45:02.633 real tough to update stuff going back in uh.
00:45:02.643 --> 00:45:06.360 So, but uh, can I real quick just get a show of hands from
00:45:06.360 --> 00:45:08.503 everybody who's who's keeping up.
00:45:08.943 --> 00:45:09.813 Did we lose anybody?
00:45:13.893 --> 00:45:15.223 I know David said he'd be right back.
00:45:15.233 --> 00:45:17.853 So he's uh.
00:45:17.863 --> 00:45:20.093 He's excused from this role call.
00:45:20.963 --> 00:45:22.723 Umm, but OK, cool.
00:45:22.783 --> 00:45:24.583 Alright, we got everybody all right.
00:45:25.153 --> 00:45:30.839 So the next thing I want to talk about is a, uh, a concept called
00:45:30.839 --> 00:45:31.873 enumeration.
00:45:32.293 --> 00:45:34.753 Umm. So what?
00:45:34.763 --> 00:45:39.862 That what this topic sort of gets into is, umm, at what point
00:45:39.862 --> 00:45:43.893 are we actually reading stuff from the database?
00:45:44.063 --> 00:45:46.787 And Tristan, this kind of gets a little bit into the deferred
00:45:46.787 --> 00:45:48.853 execution that you were talking about earlier.
00:45:48.863 --> 00:45:53.447 But I wanna not get too much into that and just try to cover
00:45:53.447 --> 00:45:56.303 the basics on this one real quick so.
00:45:55.443 --> 00:45:55.603 Yeah.
00:45:57.663 --> 00:45:58.083 Umm.
00:45:58.643 --> 00:45:59.313 What?
00:45:59.383 --> 00:46:04.328 What enumeration means is effectively just to kind of
00:46:04.328 --> 00:46:05.793 oversimplify it.
00:46:05.803 --> 00:46:08.637 It's the point in the query where something actually goes
00:46:08.637 --> 00:46:11.618 and runs some SQL against the database and brings the result
00:46:11.618 --> 00:46:11.863 back.
00:46:12.713 --> 00:46:17.775 Umm so that's sort of the turning point. If you will where
00:46:17.775 --> 00:46:22.495 we cross from sequel land to memory land and obviously
00:46:22.495 --> 00:46:27.558 there's ups and downs of being on either side of that wall
00:46:27.558 --> 00:46:32.363 where in in database land. You're building a SQL query.
00:46:32.733 --> 00:46:34.003 It's gonna be super fast.
00:46:34.013 --> 00:46:35.463 It's gonna pull everything you need.
00:46:35.513 --> 00:46:36.083 Cool.
00:46:36.273 --> 00:46:38.804 However, there are certain things SQL in can't do like we
00:46:38.804 --> 00:46:39.983 were talking about earlier.
00:46:40.053 --> 00:46:43.137 I can't put new sales invoice model in SQL and it doesn't know
00:46:43.137 --> 00:46:43.773 what that is.
00:46:44.463 --> 00:46:46.683 Umm. Uh.
00:46:47.703 --> 00:46:50.677 And then vice versa, once it's all in memory, I can't go get
00:46:50.677 --> 00:46:53.749 anything I didn't already read out, but once it's in memory, I
00:46:53.749 --> 00:46:55.553 can do anything I can do in C sharp.
00:46:55.563 --> 00:46:59.013 I'm no longer constrained by what the database understands,
00:46:59.013 --> 00:47:02.520 so before you go hold on before you go too much further into
00:47:02.520 --> 00:47:04.073 this, I just wanna keep it.
00:47:04.413 --> 00:47:09.120 Keep it super simple real quick and just make sure that, umm,
00:47:09.120 --> 00:47:13.828 that we're that people are fully understanding uh, what we're
00:47:13.828 --> 00:47:14.663 looking at.
00:47:14.673 --> 00:47:21.968 So this first query here that that Tristan has this uh, what
00:47:21.968 --> 00:47:29.623 we've built here is that we have a query that filters by active
00:47:29.623 --> 00:47:32.613 and selects the ID right?
00:47:32.833 --> 00:47:33.533 So that's all cool.
00:47:34.313 --> 00:47:39.113 Umm, but yes, that's exactly correct.
00:47:39.203 --> 00:47:42.543 We haven't enumerated this query yet and I'll get into seeing
00:47:42.543 --> 00:47:45.884 where the enumeration happens and all that kind of stuff, but
00:47:45.884 --> 00:47:49.386 the primary way to tell is that the type of something here is an
00:47:49.386 --> 00:47:50.033 I queryable.
00:47:52.103 --> 00:47:54.722 So you can see that the locus has I queryable is the type
00:47:54.722 --> 00:47:54.993 there.
00:47:55.263 --> 00:47:58.843 What that means is that this is not the results of a query.
00:47:58.853 --> 00:48:02.193 This is a query that has not been executed yet.
00:48:03.043 --> 00:48:06.383 Umm, so the results of this query have not come back.
00:48:07.183 --> 00:48:12.223 Umm, we haven't enumerated the query yet, So what?
00:48:12.233 --> 00:48:15.405 That allows us to do is kind of build additional things onto
00:48:15.405 --> 00:48:18.629 these filters onto this query to apply additional filters and
00:48:18.629 --> 00:48:19.513 things like that.
00:48:23.453 --> 00:48:25.863 And so yeah.
00:48:30.583 --> 00:48:32.763 Yet to do something equals something, by the way.
00:48:33.303 --> 00:48:33.743 Yeah, yeah, yeah.
00:48:34.233 --> 00:48:36.303 Yeah, it returns copies or clones.
00:48:36.313 --> 00:48:36.483 Yeah.
00:48:38.023 --> 00:48:40.951 So then we can say that if we have some condition where we
00:48:40.951 --> 00:48:43.978 need to apply an additional filter, you're you have a select
00:48:43.978 --> 00:48:45.963 ID up there, so you got to remove that.
00:48:46.833 --> 00:48:47.903 Ohh yeah, my bad.
00:48:47.953 --> 00:48:50.593 Sorry, I just feel like this or whatever.
00:48:56.333 --> 00:48:56.533 Do.
00:48:56.673 --> 00:48:57.243 Yeah.
00:48:57.303 --> 00:49:00.402 So maybe we're specifically if we pass in true, then we only
00:49:00.402 --> 00:49:03.603 wanna find invoices where the balance due is greater than 100.
00:49:03.613 --> 00:49:04.833 Otherwise we wanna find them all.
00:49:06.733 --> 00:49:10.274 You can actually kind of build on additional filters to your
00:49:10.274 --> 00:49:11.203 query like this.
00:49:11.213 --> 00:49:13.623 And once again, we have not yet enumerated.
00:49:13.633 --> 00:49:17.446 If you mouse over something, it's still I queryable and
00:49:17.446 --> 00:49:17.923 that's.
00:49:17.963 --> 00:49:19.523 I mean, that's just the C type system.
00:49:19.533 --> 00:49:21.203 A type is itself forever.
00:49:21.213 --> 00:49:22.863 A variable doesn't change type.
00:49:22.993 --> 00:49:27.121 There's no I mean, technically there is a concept of any, but
00:49:27.121 --> 00:49:31.183 we're not going to talk about that because it's bad practice
00:49:31.183 --> 00:49:34.513 to use it in C sharp and in TypeScript sometimes.
00:49:34.603 --> 00:49:36.783 Sometimes it's necessary, but anyway.
00:49:37.333 --> 00:49:41.679 Umm uh, so but again, we have not actually executed this
00:49:41.679 --> 00:49:46.482 query, so we we conditionally apply an additional where clause
00:49:46.482 --> 00:49:48.693 to this filter if we need to.
00:49:49.143 --> 00:49:51.103 But we haven't run the query yet.
00:49:51.463 --> 00:49:54.223 So how do you enumerate a query?
00:49:56.283 --> 00:49:57.993 Does anybody have a guess?
00:49:58.003 --> 00:50:01.089 Anybody wanna hazard a guess as to what part of the query
00:50:01.089 --> 00:50:02.313 actually enumerates it?
00:50:02.323 --> 00:50:03.923 What part actually goes and reads the value?
00:50:07.073 --> 00:50:08.523 Easier to list upper.
00:50:07.193 --> 00:50:07.563 If anybody.
00:50:09.963 --> 00:50:11.283 That is correct.
00:50:11.733 --> 00:50:15.113 To two list alright?
00:50:12.773 --> 00:50:14.453 Uh or the 1st, right?
00:50:13.033 --> 00:50:13.383 Yeah.
00:50:13.433 --> 00:50:16.783 So or the 1st, that's exactly right.
00:50:15.173 --> 00:50:17.523 Yes, we're the single or the OR not.
00:50:16.913 --> 00:50:21.620 So umm, the methods that enumerate a database query are
00:50:21.620 --> 00:50:23.553 the ones that actually.
00:50:24.723 --> 00:50:27.832 Specify that we're getting a list or we're getting one result
00:50:27.832 --> 00:50:30.892 that we're getting a single result, the 1st result, whatever
00:50:30.892 --> 00:50:31.193 it is.
00:50:31.403 --> 00:50:37.004 So the enumeration looks like the to list async down there
00:50:37.004 --> 00:50:38.713 online 540 uh 541.
00:50:38.723 --> 00:50:43.702 Actually I can't read or the dot first async up a little bit
00:50:43.702 --> 00:50:44.273 higher.
00:50:45.083 --> 00:50:51.303 Umm so and you can actually see that the result of those.
00:50:55.943 --> 00:50:56.813 Uh, yeah.
00:50:56.823 --> 00:50:58.213 So do you like A2 list async?
00:50:58.363 --> 00:50:58.613 Yeah.
00:50:58.623 --> 00:50:58.973 Perfect.
00:50:58.983 --> 00:51:02.383 OK, so now if you mouse over 2 list async return type.
00:51:04.763 --> 00:51:06.903 The return type of like 2 list async specifically.
00:51:08.343 --> 00:51:12.083 You'll see that it says that it returns a task of a list.
00:51:13.073 --> 00:51:15.333 The list is not an I queryable anymore.
00:51:17.453 --> 00:51:22.928 So what that means is, at that point the query will be
00:51:22.928 --> 00:51:24.023 enumerated.
00:51:25.443 --> 00:51:26.373 We're not in.
00:51:26.383 --> 00:51:27.693 I queryable anymore.
00:51:27.763 --> 00:51:28.393 We are.
00:51:28.403 --> 00:51:32.598 We are returning something else other than I queryable, so we
00:51:32.598 --> 00:51:35.373 are now officially out of database land.
00:51:35.383 --> 00:51:39.508 This is going to take all the pieces we put up there, the
00:51:39.508 --> 00:51:43.563 filter by active, the select the where online 526 if our
00:51:43.563 --> 00:51:46.693 condition was met, which obviously if true.
00:51:46.703 --> 00:51:48.613 So it always will be, but you get the picture.
00:51:49.343 --> 00:51:50.613 It will take all of that stuff.
00:51:50.623 --> 00:51:53.063 It will build its final SQL query and it'll run it.
00:51:54.813 --> 00:51:58.443 So that's the point where the query is enumerated.
00:51:59.093 --> 00:52:02.717 The results it sends the all the SQL database gets the results,
00:52:02.717 --> 00:52:06.001 gives it back to you and something that you can work with
00:52:06.001 --> 00:52:07.983 in memory or in your C sharp code.
00:52:08.543 --> 00:52:08.973 Umm.
00:52:09.623 --> 00:52:13.456 So again, just to just to kind of double down on it, clarify a
00:52:13.456 --> 00:52:16.133 little bit more, that's the breaking point.
00:52:16.203 --> 00:52:19.198 That's the point where this object you're not building a
00:52:19.198 --> 00:52:22.404 query anymore, you're you're executing it and you're working
00:52:22.404 --> 00:52:24.033 with the results of that query.
00:52:24.263 --> 00:52:26.593 Anything you didn't ask for, you don't have.
00:52:27.783 --> 00:52:31.475 That's that's the the the the the point at which you
00:52:31.475 --> 00:52:35.863 transitioned from database to result are from query to result.
00:52:35.873 --> 00:52:36.993 I guess is probably better way to say it.
00:52:37.683 --> 00:52:41.013 Umm so the the other methods.
00:52:41.023 --> 00:52:44.853 If you wanna show here, Tristan is like do like first async.
00:52:45.123 --> 00:52:45.343 Yeah.
00:52:46.593 --> 00:52:48.633 And you'll see the result on this one.
00:52:48.643 --> 00:52:53.592 If you mouse over first async, it returns a task of T source
00:52:53.592 --> 00:52:57.893 which T source is not I queryable, so it doesn't it.
00:52:57.903 --> 00:52:59.183 This is an enumerator.
00:52:59.193 --> 00:53:00.473 It enumerates the query.
00:53:00.483 --> 00:53:02.993 So, UM, so that's great.
00:53:05.353 --> 00:53:09.627 That's a very important thing to understand because you may
00:53:09.627 --> 00:53:13.403 accidentally enumerate a query before you intend to.
00:53:13.453 --> 00:53:18.173 In a lot of ways that are a little bit gotcha.
00:53:19.653 --> 00:53:25.077 So umm, before I go any further on this, does this concept makes
00:53:25.077 --> 00:53:26.663 sense to everybody?
00:53:28.433 --> 00:53:30.803 Is there anybody that's I I lose?
00:53:30.813 --> 00:53:31.183 Anybody.
00:53:31.193 --> 00:53:34.113 Everybody's good and.
00:53:33.693 --> 00:53:37.437 Guess if you're a friend and you're looking at this, you can
00:53:37.437 --> 00:53:41.303 imagine the the query piece is like the DTO before you send it
00:53:41.303 --> 00:53:44.863 to the back end and you actually have her your data back.
00:53:44.183 --> 00:53:46.453 Yes, that's a. That's a pretty good analog.
00:53:46.463 --> 00:53:46.933 Yeah.
00:53:47.023 --> 00:53:51.752 So everything we're doing up to line 529, we're building a DTO,
00:53:47.233 --> 00:53:47.533 Umm.
00:53:51.752 --> 00:53:56.408 we're building a query that gets sent to the database and then
00:53:56.408 --> 00:54:00.768 what happens on 9529 is the equivalent of you calling your
00:54:00.768 --> 00:54:04.833 CVA API dot whatever endpoint and passing your DTO to.
00:54:04.843 --> 00:54:08.221 It's very similar process, obviously syntactically it's a
00:54:08.221 --> 00:54:11.716 little bit different because we're not actually building an
00:54:11.716 --> 00:54:15.327 object here, a DTO object where it's like this like functions
00:54:15.327 --> 00:54:18.822 that kind of collapse on each other like the they call it a
00:54:18.822 --> 00:54:19.463 fluent API.
00:54:19.473 --> 00:54:22.383 But but fundamentally is very similar.
00:54:22.393 --> 00:54:23.453 That's a great analogy.
00:54:25.373 --> 00:54:27.623 So, but is everybody good?
00:54:28.223 --> 00:54:28.863 Umm.
00:54:29.063 --> 00:54:34.216 If so, we can talk a little bit more about uh with the the where
00:54:34.216 --> 00:54:39.211 part that you were talking about a little bit ago, Tristan and
00:54:39.211 --> 00:54:44.206 some of the other things that you can, uh, you can use to make
00:54:40.093 --> 00:54:40.333 Umm.
00:54:44.206 --> 00:54:46.743 queries more fancy and I'll, uh.
00:54:49.303 --> 00:54:49.733 I will.
00:54:49.743 --> 00:54:52.313 Uh, try to talk less.
00:54:52.383 --> 00:54:53.623 It's like kind of hijack this one.
00:54:53.633 --> 00:54:55.773 Sorry, this is one of those is one of those.
00:54:54.863 --> 00:54:55.533 Now you're fine.
00:54:55.543 --> 00:54:59.012 I honestly, I went into this thinking like this is gonna be
00:54:59.012 --> 00:54:59.533 back end.
00:54:59.763 --> 00:55:00.073 Only.
00:55:00.083 --> 00:55:01.793 So I was gonna go like ******** mode.
00:55:01.663 --> 00:55:02.113 Yeah.
00:55:01.803 --> 00:55:02.533 Like, not even.
00:55:02.123 --> 00:55:02.663 No, that's.
00:55:02.673 --> 00:55:04.553 Yeah, I'm glad.
00:55:03.643 --> 00:55:04.523 And I totally did.
00:55:04.603 --> 00:55:08.546 I'm actually very glad the front end team is here because I think
00:55:08.546 --> 00:55:12.370 that a lot of you guys are kind of wanting to get into back end
00:55:12.370 --> 00:55:16.015 development more or I think personally that everybody should
00:55:16.015 --> 00:55:19.003 have a good idea of what the other side is doing.
00:55:19.473 --> 00:55:21.023 We're all working on the same projects.
00:55:21.033 --> 00:55:22.533 We're all working on the same code.
00:55:22.603 --> 00:55:25.401 We should at least have an understanding of each other's
00:55:25.401 --> 00:55:28.053 jobs back in for front and in front and for back end.
00:55:28.063 --> 00:55:32.346 So I think this is fantastic that you guys are getting to see
00:55:32.346 --> 00:55:33.383 this UM and uh.
00:55:33.393 --> 00:55:36.616 So I'm glad, but and this is also one of those topics that I
00:55:36.616 --> 00:55:39.152 personally find very interesting, I really like
00:55:39.152 --> 00:55:42.587 messing with any framework stuff and query optimization is all a
00:55:42.587 --> 00:55:45.651 very fun topic and you can go really deep into it and get
00:55:45.651 --> 00:55:48.663 really there's a million different level things to know.
00:55:48.813 --> 00:55:53.923 So kind of apologies for hijacking it a little bit, but.
00:55:57.973 --> 00:56:04.004 So I guess I guess circled way way way back to the beginning if
00:56:04.004 --> 00:56:07.773 we wanted to get unpaid sales invoices.
00:56:10.213 --> 00:56:18.608 By ID and let's say and I'll just build out a select here,
00:56:18.608 --> 00:56:27.573 but Ohly get fields like select X, no I do couldn't say slept.
00:56:30.593 --> 00:56:30.933 You.
00:56:45.993 --> 00:56:49.447 Uh, it's gonna complain because this isn't of the type we're
00:56:49.447 --> 00:56:50.863 supposed to be returning.
00:56:52.703 --> 00:56:55.352 Realistically, this should be actually like sales invoice
00:56:55.352 --> 00:56:58.093 model, because you usually aren't returning entities, which
00:56:58.093 --> 00:56:59.783 means we have to do the goofy thing.
00:57:00.783 --> 00:57:01.623 Compare with me.
00:57:04.033 --> 00:57:04.983 Duh.
00:57:09.653 --> 00:57:12.083 I'm voice model.
00:57:13.193 --> 00:57:15.393 Is this a private function or one on the interface?
00:57:16.593 --> 00:57:19.769 Uh, this we're pretending this would be like one on the
00:57:19.769 --> 00:57:21.073 interface or something.
00:57:21.903 --> 00:57:25.673 Then your return type should be list of IG model.
00:57:26.873 --> 00:57:31.673 Like I sales invoice model for example yeah and then.
00:57:28.893 --> 00:57:29.093 Yep.
00:57:32.513 --> 00:57:33.483 OK, the.
00:57:33.553 --> 00:57:39.533 Uh, yeah, I'll have to do Smith.
00:57:34.023 --> 00:57:37.463 Menu .2 list of ID sales invoice model.
00:57:40.033 --> 00:57:41.803 So it's not a total.
00:57:45.203 --> 00:57:49.973 Click there and then got two list and when you do it too list
00:57:49.973 --> 00:57:54.819 you can actually do this thing with the carrots here where you
00:57:54.819 --> 00:57:59.127 can say hey I know right now this is just sales invoice
00:57:59.127 --> 00:58:03.282 models but I wanna explicitly say hey I want to be uh
00:58:03.282 --> 00:58:06.513 elicitive I sales invoice models general.
00:58:05.033 --> 00:58:05.213 Yep.
00:58:05.673 --> 00:58:10.093 You can you can downcast with that method so the the concrete
00:58:10.093 --> 00:58:14.371 is a higher level than the interface, so you're downcasting
00:58:14.371 --> 00:58:15.583 to the interface.
00:58:15.593 --> 00:58:19.513 In this case, if you need to upcast, like from the interface
00:58:19.513 --> 00:58:19.963 to the.
00:58:21.153 --> 00:58:25.165 Model you have to call cast with the alligator clips of the model
00:58:25.165 --> 00:58:28.812 type and then after that do .2 list because two list itself
00:58:28.812 --> 00:58:29.663 cannot upcast.
00:58:36.683 --> 00:58:37.633 So I'll just point that out.
00:58:40.783 --> 00:58:46.633 OK, so at this point I'll zoom out a little bit.
00:58:46.743 --> 00:58:50.454 It's gonna start getting old tactic, but if we wanted to get
00:58:50.454 --> 00:58:54.348 unpaid sales invoices by the we would need an additional clause
00:58:54.348 --> 00:58:57.573 and like we kind of said what that is like 30 times.
00:58:57.583 --> 00:59:01.663 But can anyone tell me what what we would have to add right here?
00:59:02.933 --> 00:59:03.993 Where did you say it?
00:59:06.683 --> 00:59:07.493 Where?
00:59:07.543 --> 00:59:08.083 Where did I?
00:59:09.833 --> 00:59:10.283 Yeah.
00:59:10.293 --> 00:59:11.333 Where our claws?
00:59:10.443 --> 00:59:10.623 Hey.
00:59:11.913 --> 00:59:12.383 That was.
00:59:12.393 --> 00:59:12.963 That was funny.
00:59:13.663 --> 00:59:14.073 Nice.
00:59:14.643 --> 00:59:16.733 Yeah, but we need to wear clause.
00:59:16.843 --> 00:59:21.100 And much like the syntax and the rest of this link stuff, it's
00:59:21.100 --> 00:59:24.885 just X Lambda and then we can start, you know adding in
00:59:24.885 --> 00:59:29.143 filters basically right, just like a where clause in SQL where
00:59:29.143 --> 00:59:33.535 hey, we only want to get things with the certain status or state
00:59:33.535 --> 00:59:35.563 or balance due above whatever.
00:59:35.573 --> 00:59:39.935 So like for example I could say hey, I only want to get things
00:59:39.935 --> 00:59:42.843 the balance due greater than zero, right?
00:59:42.853 --> 00:59:46.661 And that's that's a that will only return records that have a
00:59:46.661 --> 00:59:49.363 balanced greater than zero that are active.
00:59:49.573 --> 00:59:50.713 Obviously there's more to it.
00:59:50.723 --> 00:59:54.936 Like when I build out my example query and the nucleo article I
00:59:54.936 --> 00:59:59.017 put in chat, I was checking the status is too right, so if it
00:59:59.017 --> 01:00:03.230 says it's paid or it's void and I'm making sure it's not like a
01:00:03.230 --> 01:00:07.047 state of history which means it's basically a record that
01:00:07.047 --> 01:00:09.483 shouldn't get updated in the future.
01:00:09.523 --> 01:00:14.590 Hopefully umm or even and this is more like specific to where
01:00:14.590 --> 01:00:16.143 surcharging exists.
01:00:16.633 --> 01:00:20.834 Mainly pay hub I think, but we also don't want if it has, like
01:00:20.834 --> 01:00:24.768 if it's a surcharge invoice, we don't want to return those
01:00:24.768 --> 01:00:28.903 either, but either way I guess to keep it stupid simple, hmm.
01:00:26.333 --> 01:00:30.293 After your wear line, will you add a dot filter?
01:00:33.063 --> 01:00:34.083 Sales invoices.
01:00:37.733 --> 01:00:41.153 By Min balance due.
01:00:44.123 --> 01:00:44.463 Ah.
01:00:44.443 --> 01:00:49.093 And then open parentheses and then you can put in your put in
01:00:49.093 --> 01:00:49.993 like 0.0001.
01:00:52.993 --> 01:00:53.443 M.
01:00:58.063 --> 01:01:01.123 That is effectively going to be the same as your what you have
01:00:58.613 --> 01:00:58.803 I.
01:01:01.123 --> 01:01:01.463 on 542.
01:01:02.963 --> 01:01:03.333 OK.
01:01:03.343 --> 01:01:03.863 Yeah.
01:01:03.923 --> 01:01:04.153 Huh.
01:01:05.363 --> 01:01:09.654 Is there like a I wish there was like the same thing, but just
01:01:09.654 --> 01:01:11.493 like greater then is there?
01:01:11.353 --> 01:01:12.003 Yeah, it does.
01:01:11.503 --> 01:01:12.173 Is there one or no?
01:01:12.153 --> 01:01:12.853 It does not.
01:01:13.073 --> 01:01:16.450 So the the min balance is gonna do a greater than the value that
01:01:16.450 --> 01:01:19.775 you've put your pasting in, but it's gonna do a greater than or
01:01:19.775 --> 01:01:20.243 equal to.
01:01:21.653 --> 01:01:21.973 Umm.
01:01:22.643 --> 01:01:26.003 Which is why I added the the the 01 thing at the end there.
01:01:25.933 --> 01:01:26.193 Yeah.
01:01:27.303 --> 01:01:30.816 I do not have it auto generating ones that just say greater than
01:01:30.816 --> 01:01:31.573 at the moment.
01:01:32.263 --> 01:01:36.353 I may do that in the future, but yeah there is mins and there.
01:01:35.033 --> 01:01:35.213 Yeah.
01:01:36.363 --> 01:01:40.618 So I think that's like a date, a number or whatever should be
01:01:40.618 --> 01:01:45.079 auto generating matches mins and maxes as values on those things
01:01:45.079 --> 01:01:48.373 so that you can constrain stuff between values.
01:01:51.733 --> 01:01:52.263 Perfect.
01:01:52.573 --> 01:01:55.293 So as an example.
01:01:57.103 --> 01:01:59.940 Just to keep it so they yeah, there's tons of like I don't
01:01:59.940 --> 01:02:03.113 think Rider actually does a good job of showing me what the like.
01:02:03.123 --> 01:02:07.980 It doesn't even do autocomplete for all the all the filter buys
01:02:07.980 --> 01:02:12.685 which kind of sucks, because then I have to remember them all
01:02:12.685 --> 01:02:15.873 and I can't just let the ID drive for me.
01:02:16.523 --> 01:02:22.583 But in terms of filtering by let's say umm, well, let's say
01:02:22.583 --> 01:02:26.523 we don't want to return void invoices.
01:02:26.533 --> 01:02:27.233 How could we do that?
01:02:33.633 --> 01:02:34.303 Filter.
01:02:34.353 --> 01:02:38.293 Ohh it's are you asking how to filter by like a status?
01:02:39.633 --> 01:02:42.337 Yeah, I guess I was kind of like I was leaving it open for anyone
01:02:41.363 --> 01:02:45.163 You went to, you went to exclude a status specifically.
01:02:42.337 --> 01:02:43.443 who wanted to jump in, but.
01:02:46.033 --> 01:02:46.973 Yeah, sure.
01:02:46.983 --> 01:02:48.523 Let's say we want to exclude a status.
01:02:50.243 --> 01:02:51.793 K dot filter.
01:02:54.103 --> 01:02:57.513 I I have a status basis.
01:02:58.703 --> 01:03:01.093 I think it's just filter by excluded status Key isn't?
01:03:01.103 --> 01:03:01.713 I think there's a.
01:03:02.503 --> 01:03:03.173 I can't remember.
01:03:03.183 --> 01:03:05.624 It's so some of those I have the the the first part on there and
01:03:05.624 --> 01:03:06.413 some of them I don't.
01:03:07.023 --> 01:03:10.723 And if you're only doing one, then you can do that and you can
01:03:07.983 --> 01:03:08.303 Ohh yeah.
01:03:10.723 --> 01:03:13.483 pass in the key and then you do a strict true.
01:03:14.663 --> 01:03:15.643 So you put your vote your.
01:03:17.063 --> 01:03:18.513 Yeah, your void and then true.
01:03:19.643 --> 01:03:23.813 UM and then because that one doesn't understand it's type
01:03:23.283 --> 01:03:23.993 But doing dumb here.
01:03:23.813 --> 01:03:28.270 arguments, you'll have to add the alligator clips and put the
01:03:28.270 --> 01:03:29.133 types on it.
01:03:29.843 --> 01:03:31.963 So sales invoice and sales invoice status.
01:03:39.333 --> 01:03:39.783 OK.
01:03:39.853 --> 01:03:40.143 Yeah.
01:03:40.153 --> 01:03:40.273 Cool.
01:03:42.093 --> 01:03:43.383 So yeah, for example.
01:03:42.533 --> 01:03:45.819 And there was a plural version of that that does it, where you
01:03:45.819 --> 01:03:47.593 can pass in an array of statuses.
01:03:49.123 --> 01:03:54.293 So like if you want to avoid void and paid or whatever, you
01:03:51.013 --> 01:03:51.173 Yeah.
01:03:54.293 --> 01:03:57.653 can pass them in together as an array.
01:03:59.033 --> 01:03:59.373 OK.
01:03:59.383 --> 01:03:59.703 Yeah.
01:03:59.713 --> 01:04:04.033 So I could do like news array or whatever like do like Floyd.
01:04:02.773 --> 01:04:07.298 And then you'll you'll take the true off because in in this case
01:04:07.298 --> 01:04:11.475 it it enforces true always like you can't specify not true,
01:04:11.475 --> 01:04:11.823 yeah.
01:04:13.243 --> 01:04:15.283 Looks like out of the COM on the wrong side there.
01:04:16.063 --> 01:04:18.223 Uh, what else did I do wrong?
01:04:21.603 --> 01:04:23.903 Cannot access private method here.
01:04:24.433 --> 01:04:26.083 Yeah, sometimes they'll be private.
01:04:26.313 --> 01:04:28.063 So you just go to the function and make it public.
01:04:28.223 --> 01:04:29.273 If you're actually going to use it.
01:04:28.673 --> 01:04:28.973 OK.
01:04:33.303 --> 01:04:34.913 So what's that gonna be?
01:04:35.023 --> 01:04:35.633 Would it be in here?
01:04:35.603 --> 01:04:36.693 It's that private stat.
01:04:35.643 --> 01:04:36.093 No, it's not.
01:04:36.703 --> 01:04:37.433 It just go back to that.
01:04:37.443 --> 01:04:38.983 There's a private static, you know right there.
01:04:39.873 --> 01:04:40.383 OK.
01:04:40.433 --> 01:04:43.433 Yeah, proposed to make that public.
01:04:41.103 --> 01:04:41.243 Yeah.
01:04:44.673 --> 01:04:45.903 Now this is complaining.
01:04:44.983 --> 01:04:47.123 This is going to complain about where it is in the file.
01:04:46.433 --> 01:04:47.673 Yeah, whatever.
01:04:47.133 --> 01:04:48.493 Has to be before the other privacy.
01:04:47.683 --> 01:04:48.103 Role.
01:04:48.303 --> 01:04:48.463 Yeah.
01:04:48.503 --> 01:04:49.253 Yeah, it doesn't matter.
01:04:49.073 --> 01:04:49.563 We won't.
01:04:49.263 --> 01:04:49.663 Well, yeah.
01:04:49.633 --> 01:04:52.901 We won't worry about that, but assuming that was already
01:04:52.901 --> 01:04:53.303 public.
01:04:53.313 --> 01:04:57.016 Yeah, like you could do this, which is cool, because even I
01:04:57.016 --> 01:05:00.719 don't know all these filter buys and the one thing I I GIMP
01:05:00.719 --> 01:05:04.731 myself on by using rider is that I actually don't get to see all
01:05:04.731 --> 01:05:07.323 these, which is the the one crappy thing.
01:05:07.333 --> 01:05:10.657 And I wonder if there's a way we can fix that, but if there is,
01:05:10.657 --> 01:05:12.943 if anyone knows, that would be pretty sick.
01:05:13.003 --> 01:05:17.593 Because this is, this is basically like Visual Studio
01:05:17.593 --> 01:05:21.843 with Resharper but not laggy if that makes sense.
01:05:22.193 --> 01:05:24.253 If anyone's trying to, I mean.
01:05:22.713 --> 01:05:23.233 Umm.
01:05:23.573 --> 01:05:25.303 Press control alt S.
01:05:27.013 --> 01:05:28.733 Troll Alt S.
01:05:30.243 --> 01:05:33.253 That's supposed to bring up the settings screen and then you
01:05:33.253 --> 01:05:35.523 need to go to editor general code completion.
01:05:38.873 --> 01:05:39.423 Umm.
01:05:39.803 --> 01:05:41.153 At her general.
01:05:41.163 --> 01:05:45.423 And then interior and then code completion. Uh.
01:05:44.903 --> 01:05:47.522 And then that's where the settings around the code
01:05:47.522 --> 01:05:48.293 completion are.
01:05:49.053 --> 01:05:51.283 Yeah, to this list.
01:05:51.093 --> 01:05:51.623 Uh.
01:05:51.633 --> 01:05:54.736 Because like, it's got suggestions clearly to do that
01:05:54.736 --> 01:05:55.253 and then.
01:05:56.973 --> 01:05:57.963 Find the C sharp side.
01:05:57.973 --> 01:05:59.323 There's a JavaScript section here.
01:05:59.333 --> 01:06:00.883 There might be a C sharp section.
01:06:03.373 --> 01:06:04.023 Terms of.
01:06:05.773 --> 01:06:08.664 I mean on the rights of the feeling is like JavaScript and
01:06:07.393 --> 01:06:07.783 Ohh.
01:06:08.664 --> 01:06:11.849 the right section, there's SQL, JSON just keeps growing as their
01:06:11.849 --> 01:06:14.103 cities, India like a C sharp section in here.
01:06:12.623 --> 01:06:13.183 Yeah, I didn't.
01:06:15.293 --> 01:06:16.913 I didn't say anything specific.
01:06:18.103 --> 01:06:20.623 Umm, I don't know.
01:06:18.273 --> 01:06:18.893 Me neither.
01:06:20.633 --> 01:06:20.983 I might.
01:06:21.033 --> 01:06:21.683 I might look.
01:06:21.673 --> 01:06:23.043 Yeah, play with that later, yeah.
01:06:21.693 --> 01:06:22.763 I'll look into it later on.
01:06:22.413 --> 01:06:22.733 I don't know.
01:06:23.853 --> 01:06:24.123 Yeah.
01:06:24.133 --> 01:06:26.894 If if it's on, it's supposed to basically like as you just as
01:06:24.143 --> 01:06:25.443 I don't want to derail stuff, but.
01:06:26.894 --> 01:06:29.522 you type, it's supposed to be just bring up the a sub menu
01:06:29.522 --> 01:06:31.793 that looks like the Intellisense in Visual Studio.
01:06:32.973 --> 01:06:35.893 Umm to make the suggestions of what it's typing.
01:06:38.483 --> 01:06:38.733 Thing?
01:06:38.743 --> 01:06:39.803 Alex asked a question.
01:06:42.253 --> 01:06:45.913 So that's a great question. Umm.
01:06:45.683 --> 01:06:45.963 Umm.
01:06:48.313 --> 01:06:51.907 The uh, the way, you know, is to just look and see if that method
01:06:51.907 --> 01:06:55.119 exists and if you're using full Visual Studio, you can use
01:06:55.119 --> 01:06:58.223 Intellisense, which is kind of what we're talking about,
01:06:58.223 --> 01:06:58.713 actually.
01:06:58.723 --> 01:07:01.679 Let me I'll pull up 1 real quick and show you what that how to
01:07:01.679 --> 01:07:04.353 kind of use that intelligence to see what it looks like.
01:07:02.133 --> 01:07:02.333 Yeah.
01:07:05.343 --> 01:07:09.317 Just give me a little because Visual Studio is Visual Studio
01:07:09.317 --> 01:07:13.225 and it will take a moment to load so, but that's a that's a
01:07:10.813 --> 01:07:13.393 Yeah, essentially if you type filter by.
01:07:12.113 --> 01:07:17.040 Uh, and and I'll, I'll I'll preface that with basically a a
01:07:13.225 --> 01:07:14.463 fantastic question.
01:07:17.040 --> 01:07:19.833 **** load of these things exists.
01:07:20.303 --> 01:07:22.922 There are tons and tons of them that do all kinds of different
01:07:20.393 --> 01:07:20.653 Yeah.
01:07:22.922 --> 01:07:23.213 things.
01:07:23.343 --> 01:07:26.646 So it almost always, in almost every case, there's one that
01:07:26.646 --> 01:07:28.133 does what you needed to do.
01:07:29.123 --> 01:07:32.112 If you're doing a check against the simple property, if you're
01:07:32.112 --> 01:07:34.958 doing like an advanced query where like this has to be this
01:07:34.958 --> 01:07:37.900 and this and this and this and this all the same time, that's
01:07:37.900 --> 01:07:39.323 probably we're gonna do aware.
01:07:39.383 --> 01:07:42.509 But if it's one property that just needs to be either either a
01:07:42.509 --> 01:07:45.040 particular value or not a particular value or or a
01:07:45.040 --> 01:07:48.117 particular group of values, then there's probably a filter by
01:07:48.117 --> 01:07:48.713 that exists.
01:07:50.253 --> 01:07:54.613 And again, I'll show you how to check for those and I'll talk a
01:07:54.613 --> 01:07:58.633 little bit about where you might not see these and we are.
01:07:58.963 --> 01:07:59.613 Thank you, Michael.
01:07:59.623 --> 01:08:02.737 Let's yeah, the screen shot that Michael sent is when you're
01:08:02.737 --> 01:08:05.953 working on a query here where you would normally type where if
01:08:05.953 --> 01:08:08.863 you just type dot filter, your intelligence will pop up.
01:08:09.003 --> 01:08:12.446 A crap load of these suggestions and what you can do is Visual
01:08:12.446 --> 01:08:15.453 Studio is very smart about how it finds a suggestions.
01:08:15.683 --> 01:08:18.854 So if you type dot filter status, uh and quite capitalized
01:08:18.854 --> 01:08:22.240 status, then what it'll do is it'll find it'll find extensions
01:08:22.240 --> 01:08:25.465 that have the word filter and status in them and you can so
01:08:25.465 --> 01:08:29.013 you if you know you're filtering by like a status of whatever, or
01:08:29.013 --> 01:08:32.238 you're filtering with something related to status, then you
01:08:32.238 --> 01:08:35.678 could just type filters status and find the one that looks like
01:08:35.678 --> 01:08:38.473 it does what you needed to do by based on its name.
01:08:38.483 --> 01:08:41.656 Or maybe it's a filter balance and find the one that matches
01:08:41.656 --> 01:08:42.853 all that kind of stuff.
01:08:42.923 --> 01:08:46.793 That's kind of typically how I find them.
01:08:46.803 --> 01:08:50.572 If I'm not sure what exists, and sometimes there are more complex
01:08:50.572 --> 01:08:54.227 ones that are useful and I can't think of any off the top of my
01:08:54.227 --> 01:08:54.513 head.
01:08:55.413 --> 01:08:58.432 And and some of them like this one that but that that was
01:08:58.432 --> 01:09:01.503 private originally may not show up in that list initially.
01:09:01.733 --> 01:09:06.425 If you still wanna find it if in Visual Studio. It's the default.
01:09:06.425 --> 01:09:08.843 One is control. T is the hot key.
01:09:09.133 --> 01:09:10.503 I think it's the same in writer.
01:09:10.613 --> 01:09:13.812 And then if you had Resharper installed, Resharper version of
01:09:10.773 --> 01:09:11.013 Yeah.
01:09:13.812 --> 01:09:16.959 that would take over, but the control that you could type in
01:09:16.959 --> 01:09:20.157 that same thing and it will go find the definition of it even
01:09:20.157 --> 01:09:20.983 if it's private.
01:09:21.213 --> 01:09:23.687 And then you can make it public so that it will show up inside
01:09:23.687 --> 01:09:25.023 your Intellisense for you to use.
01:09:24.513 --> 01:09:24.973 Yeah.
01:09:25.293 --> 01:09:32.251 And what I'll show real quick is Visual Studio is ridiculously
01:09:32.251 --> 01:09:32.803 slow.
01:09:33.013 --> 01:09:35.553 Let's find a spot where I've got a database context or something.
01:09:33.673 --> 01:09:39.038 The filter the filter by Jason Objects one is one that's like
01:09:39.038 --> 01:09:42.153 kind of, you know advanced and and.
01:09:41.533 --> 01:09:43.063 It's it's cool to use.
01:09:43.073 --> 01:09:46.485 I'll say that we should avoid using it where we can, because
01:09:45.153 --> 01:09:45.463 Yeah.
01:09:46.485 --> 01:09:48.723 while functional it is not fast at all.
01:09:49.273 --> 01:09:53.031 It's a lot of very yeah, it's a lot of really gross manual
01:09:49.403 --> 01:09:49.683 Yeah.
01:09:49.423 --> 01:09:50.443 Yeah, that one's really slow.
01:09:53.031 --> 01:09:56.980 string parsing and it works in a pinch, but we shouldn't ever
01:09:56.980 --> 01:10:00.483 hinge on that being like we shouldn't default to that.
01:10:00.493 --> 01:10:04.359 That should be like, well, crap, we're 5 minutes out from go live
01:10:04.359 --> 01:10:05.823 and we have nothing else.
01:10:05.833 --> 01:10:06.283 We can't.
01:10:06.293 --> 01:10:07.023 We work all this.
01:10:07.033 --> 01:10:08.733 Let's just use that for now and we'll fix it later.
01:10:10.433 --> 01:10:15.140 Or if it's not a hot code path or even hot code path of jslint,
01:10:15.140 --> 01:10:16.243 then it's fine.
01:10:16.313 --> 01:10:21.868 But what I wanted to show real quick, ignore this giant core
01:10:21.868 --> 01:10:23.143 here or don't.
01:10:23.153 --> 01:10:25.905 If you want to look at it and kind of see some neat stuff
01:10:25.905 --> 01:10:27.613 that's a bit more of a complex one.
01:10:28.343 --> 01:10:31.263 Uh, not really complex, just larger.
01:10:31.483 --> 01:10:35.658 But what I wanted to show was a couple of neat things about how
01:10:35.658 --> 01:10:37.093 these extensions work.
01:10:37.383 --> 01:10:42.755 Uh, or how to find them and and even further cool ways to do
01:10:42.755 --> 01:10:46.013 some custom stuff and make your own.
01:10:46.143 --> 01:10:50.643 So for example umm, let's see context dot lots.
01:10:50.653 --> 01:10:52.943 And let's say that I want to filter.
01:10:54.003 --> 01:10:56.113 Uh user?
01:10:56.123 --> 01:10:56.913 Let's see.
01:10:57.063 --> 01:10:58.583 OK, so none of these are applicable.
01:11:00.153 --> 01:11:04.488 Specifically, let's say I'm trying to filter a lots by those
01:11:04.488 --> 01:11:06.763 that a specific user has bid on.
01:11:06.773 --> 01:11:09.351 And let's say that I have that user's ID, so I've got a user ID
01:11:09.351 --> 01:11:09.553 here.
01:11:09.563 --> 01:11:12.462 I wanna find a lot that this person's bid on before or all
01:11:12.462 --> 01:11:14.133 lots that this person has bid on.
01:11:14.793 --> 01:11:15.333 Umm.
01:11:16.093 --> 01:11:19.447 So obviously you know filter by active true just because that's
01:11:19.447 --> 01:11:20.443 kind of a standard.
01:11:21.433 --> 01:11:24.893 He did lots and we'll give it an away.
01:11:24.903 --> 01:11:27.423 Sure, there's nothing that does this already.
01:11:28.143 --> 01:11:32.189 I I checked and none of these are quite what I need, so I
01:11:32.189 --> 01:11:34.003 probably have to do aware.
01:11:34.853 --> 01:11:39.352 Uh, and there's a bids property on these, if any of these bids
01:11:39.352 --> 01:11:43.851 have a user ID equal to the user ID we passed into this method
01:11:43.851 --> 01:11:48.136 then that means that the user has placed some bid on it and
01:11:48.136 --> 01:11:48.993 that's cool.
01:11:49.523 --> 01:11:53.734 Now, if you're working on a bidding website, this filter is
01:11:53.734 --> 01:11:57.033 probably something you're going to call a lot.
01:11:57.403 --> 01:12:02.014 You're probably gonna want to be able to filter lots by those a
01:12:02.014 --> 01:12:06.193 user has bid on a million times, so you can make a custom
01:12:06.193 --> 01:12:10.228 extension here that looks something like filter lots by
01:12:10.228 --> 01:12:11.813 user, has bid user ID.
01:12:12.003 --> 01:12:15.090 We can make a method that does exactly this, and it just turns
01:12:15.090 --> 01:12:17.883 into this right here, and I can show you how to do that.
01:12:19.003 --> 01:12:23.528 So the place in the code that we put those extensions is any data
01:12:23.528 --> 01:12:25.653 access layer searching project.
01:12:26.383 --> 01:12:29.024 You open this up and like most places it's separated out by
01:12:29.024 --> 01:12:31.753 schema, just like in the data model, the workflows et cetera.
01:12:32.193 --> 01:12:35.778 And in this case, it's in auctions and we're looking at
01:12:35.778 --> 01:12:38.723 lot and we've already got a lot dot extended.
01:12:38.733 --> 01:12:41.328 If we didn't, we would just make one called bot dot extended dot
01:12:41.328 --> 01:12:43.803 CS and we could follow the style of any of the other extended
01:12:43.803 --> 01:12:44.003 ones.
01:12:44.013 --> 01:12:46.043 But we already have it great.
01:12:46.273 --> 01:12:48.415 So I'm gonna put this over here just so it's on the other side
01:12:48.415 --> 01:12:50.013 and you can see what a lot of these look like.
01:12:50.423 --> 01:12:54.409 Umm, so you can see filter lots by product grade filter lots by
01:12:54.409 --> 01:12:57.897 minimum, maximum quantity by products manufacturer part
01:12:57.897 --> 01:12:58.333 number.
01:12:58.483 --> 01:13:01.324 So these are some that we're already custom built for PCs
01:13:01.324 --> 01:13:04.263 because we needed them along the way, which is pretty cool.
01:13:08.783 --> 01:13:14.763 Formatting on this one a little bit weird, but So what?
01:13:14.773 --> 01:13:16.383 These methods are actually doing.
01:13:16.393 --> 01:13:21.132 They're called extension methods in C, and you can write these
01:13:21.132 --> 01:13:23.013 technically for anything.
01:13:23.863 --> 01:13:28.302 In our case, right now I'm just making a query extension, but
01:13:28.302 --> 01:13:32.382 you'll go into this file and you'll see that needs to be
01:13:32.382 --> 01:13:36.893 public and static, and in our case we have an I queryable lot.
01:13:37.023 --> 01:13:38.353 That's our type that we returned.
01:13:38.363 --> 01:13:41.360 You can see that I'm kind of just following the Convention up
01:13:41.360 --> 01:13:43.003 here based on what these do. Umm.
01:13:43.673 --> 01:13:45.243 And we called it filter.
01:13:45.253 --> 01:13:49.820 Lots by user has bid and the first thing we have to do is put
01:13:49.820 --> 01:13:51.883 this this I queryable query.
01:13:52.863 --> 01:13:55.793 That's the C sharp extension method syntax.
01:13:55.873 --> 01:13:59.991 That's basically saying that the word this uh here denotes that
01:13:59.991 --> 01:14:01.793 this is an extension method.
01:14:01.803 --> 01:14:05.462 And what that basically says is you can call this method on an I
01:14:05.462 --> 01:14:08.672 queryable of lot and that inquiry will be passed in as a
01:14:08.672 --> 01:14:10.023 parameter in the method.
01:14:11.443 --> 01:14:17.325 And then we the parameter that we actually want for this is a
01:14:17.325 --> 01:14:23.112 user ID, so we go into here and we can say if the user ID is
01:14:23.112 --> 01:14:28.993 invalid then we don't want to change anything, we just return
01:14:28.993 --> 01:14:33.073 the query exactly as it is, UM, otherwise.
01:14:33.083 --> 01:14:34.823 Or maybe we wanna throw an exception or something.
01:14:34.833 --> 01:14:35.193 I don't know.
01:14:35.203 --> 01:14:37.303 Whatever you want it to do, umm.
01:14:37.543 --> 01:14:39.453 But otherwise we want to do a query.
01:14:39.553 --> 01:14:45.313 Where exactly what I put over here goes right here and now?
01:14:46.443 --> 01:14:50.939 This sort of chains into this and adds this filter on to this
01:14:50.939 --> 01:14:55.218 query and then whenever we list it out, it'll have that on
01:14:55.218 --> 01:14:55.653 there.
01:14:55.943 --> 01:14:58.908 So that's kind of an example of how you can make your own and
01:14:58.908 --> 01:15:01.920 you can see that it also lit up and doesn't have an error over
01:15:01.920 --> 01:15:04.694 here because it's actually finding this one which is very
01:15:04.694 --> 01:15:04.933 cool.
01:15:05.583 --> 01:15:12.395 So that that is how you get it those or make your own custom
01:15:12.395 --> 01:15:13.623 extensions.
01:15:13.633 --> 01:15:14.103 You can.
01:15:14.153 --> 01:15:18.507 These can be again, as long as you're returning an I queryable
01:15:18.507 --> 01:15:21.203 and not doing anything overly strange.
01:15:21.213 --> 01:15:22.723 These can be as complex as you want.
01:15:22.733 --> 01:15:28.292 We could even do one that's uh lot filter lots by user is
01:15:28.292 --> 01:15:28.963 hybrid.
01:15:30.193 --> 01:15:32.989 Do we have any custom extensions for stuff that aren't, uh, query
01:15:30.423 --> 01:15:31.083 Uh, that's.
01:15:32.989 --> 01:15:33.243 ables?
01:15:33.613 --> 01:15:36.203 You know, just for, I don't know, Rando.
01:15:34.773 --> 01:15:39.093 Oh, yeah, yeah, I yeah, let me see if I I.
01:15:36.213 --> 01:15:37.373 I have like strings.
01:15:38.243 --> 01:15:41.493 If you look down in core utilities, I have a **** load of
01:15:41.493 --> 01:15:44.912 exemptions for all kinds of stuff, like a like like a string
01:15:42.153 --> 01:15:43.023 Hey, right on.
01:15:42.373 --> 01:15:43.203 Is somewhere.
01:15:44.912 --> 01:15:48.443 dot split camel case that will turn it into more of a sentence
01:15:47.223 --> 01:15:49.083 Yeah, string extensions, yeah.
01:15:48.443 --> 01:15:48.723 case.
01:15:49.123 --> 01:15:49.573 There you go.
01:15:49.273 --> 01:15:50.443 Ah well.
01:15:49.663 --> 01:15:50.513 So yeah, same thing.
01:15:50.523 --> 01:15:53.675 Two SEO URL this string source and it collapses things that are
01:15:53.503 --> 01:15:53.663 Yeah.
01:15:53.675 --> 01:15:55.843 invalid and then replaces them with dashes.
01:15:56.003 --> 01:15:57.283 Oh, that's really good.
01:15:56.643 --> 01:15:58.843 You could make extensions on anything so.
01:15:58.693 --> 01:15:59.013 No.
01:15:58.843 --> 01:16:00.573 Yeah, any type can be extended.
01:15:59.023 --> 01:16:00.243 Yeah, I I knew you could.
01:16:00.253 --> 01:16:04.253 Uh, but right on, we got a bunch, didn't know.
01:16:00.583 --> 01:16:05.102 Yeah, I wrote one recently that it collapses duplicate
01:16:05.102 --> 01:16:10.114 characters in strings, so you can do like like uh, let's say
01:16:10.114 --> 01:16:11.593 you have a string.
01:16:11.603 --> 01:16:11.883 It's like.
01:16:13.653 --> 01:16:19.293 EE TER and it would change it to Peter, right?
01:16:15.863 --> 01:16:18.273 Yeah, E eater.
01:16:18.283 --> 01:16:18.933 Yeah.
01:16:19.303 --> 01:16:20.333 But it just changed it to Peter.
01:16:19.303 --> 01:16:24.050 And then if you did dot, I don't have it in this project, but
01:16:24.050 --> 01:16:28.184 it's like just collapse duplicates of E then it would
01:16:24.343 --> 01:16:27.653 But what if you put in Griffin I up?
01:16:27.943 --> 01:16:28.953 You see, that's right.
01:16:28.184 --> 01:16:29.333 trim this down.
01:16:29.343 --> 01:16:35.621 The result of this would be uh, if stir equals here, then this
01:16:35.621 --> 01:16:38.013 would happen right here.
01:16:38.443 --> 01:16:39.583 Yeah, right on.
01:16:38.753 --> 01:16:42.233 Umm, there you can do extensions on anything.
01:16:42.243 --> 01:16:42.853 Very cool.
01:16:43.663 --> 01:16:49.430 Yeah, we can come in here and try to write this as fast as I
01:16:47.153 --> 01:16:47.613 Yeah, sorry.
01:16:49.430 --> 01:16:53.873 can turn query where bids order by descending.
01:16:59.233 --> 01:17:00.063 Current bid.
01:17:00.073 --> 01:17:04.635 So we have, we're saying where the bids ordered by descending
01:17:04.635 --> 01:17:09.344 the first one, which you have to use first or default here I'll
01:17:09.344 --> 01:17:12.803 talk about later user ID equals that user umm.
01:17:13.013 --> 01:17:17.193 Umm, one extra piece in this is that on both of these things?
01:17:17.313 --> 01:17:21.823 You need to do active checks in case the stuff was soft deleted.
01:17:20.523 --> 01:17:21.973 Oh yeah, I I put one over.
01:17:22.043 --> 01:17:23.063 Ohly talking about the bids.
01:17:23.073 --> 01:17:23.783 Yeah, you're right.
01:17:23.893 --> 01:17:26.273 Yeah, like the bits that are inside there need active checks.
01:17:25.593 --> 01:17:26.023 Yeah.
01:17:26.033 --> 01:17:28.213 So why dot active and yeah.
01:17:33.383 --> 01:17:35.283 So this would just need to be an additional where.
01:17:39.293 --> 01:17:42.995 Which I can't do a filter by active here for complicated
01:17:42.995 --> 01:17:46.113 reasons that are, uh, unfortunately annoying to
01:17:46.113 --> 01:17:46.633 explain.
01:17:48.503 --> 01:17:52.935 But yeah, technically technically this is an eye
01:17:48.673 --> 01:17:51.703 It can't translate the the the code into C cool.
01:17:52.935 --> 01:17:58.542 collection, but it's inside of an expression that's part of a
01:17:58.542 --> 01:18:00.713 queryable, so it's fine.
01:18:00.763 --> 01:18:02.293 It's very confusing.
01:18:02.383 --> 01:18:04.453 Not really too much to.
01:18:04.783 --> 01:18:08.836 I don't wanna go too deep into that, but but ultimately what it
01:18:08.836 --> 01:18:12.636 boils down to is technically this is an eye collection, not
01:18:12.636 --> 01:18:13.713 an eye queryable.
01:18:13.723 --> 01:18:16.263 And all of our filter buyers operate on inquiry, ables.
01:18:17.113 --> 01:18:22.213 Umm so, but anyway, that's that's the majority of it.
01:18:22.223 --> 01:18:27.060 So I I hope that this was good as anybody have any additional
01:18:27.060 --> 01:18:31.273 questions and like Chris said, we are just past time.
01:18:31.283 --> 01:18:37.923 So everybody is free to to drop and have a fantastic weekend.
01:18:37.993 --> 01:18:44.083 But I'm also happy to answer any questions, so yeah.
01:18:38.283 --> 01:18:44.083 Thank you so much, Tristan and Brendan and JG was awesome.
01:18:40.743 --> 01:18:46.021 Does the does the this operator there turn it into an eye
01:18:46.021 --> 01:18:49.843 collection like how does it become a not.
01:18:48.713 --> 01:18:49.093 Right here.
01:18:49.853 --> 01:18:50.303 Yeah.
01:18:50.313 --> 01:18:54.455 Well, like, yeah, when we pass it in, we say it takes a this I
01:18:54.113 --> 01:18:58.764 No, it's the the the icollection is because it's the associated
01:18:54.455 --> 01:18:55.113 queryable.
01:18:58.423 --> 01:18:59.493 Yeah, it's bids.
01:18:58.764 --> 01:19:00.653 property that dot bids it.
01:18:59.503 --> 01:19:02.243 Yeah, bids is an IE collection of bids.
01:19:00.273 --> 01:19:01.163 Ohh sorry.
01:19:00.663 --> 01:19:02.823 That's the I collection, yeah.
01:19:01.173 --> 01:19:02.383 OK. Yeah.
01:19:02.253 --> 01:19:05.493 Yeah, not it's not an I queryable, so it doesn't.
01:19:02.773 --> 01:19:03.363 OK. Yeah.
01:19:05.503 --> 01:19:08.251 This and all of our extension methods specifically say they
01:19:05.673 --> 01:19:05.893 Yeah.
01:19:08.251 --> 01:19:11.182 operate on an I queryable, not icollection or ienumerable or et
01:19:09.003 --> 01:19:10.033 And I queryable.
01:19:10.043 --> 01:19:12.693 Yeah, yeah.
01:19:11.182 --> 01:19:11.503 cetera.
01:19:12.423 --> 01:19:12.583 Yeah.
01:19:12.423 --> 01:19:13.283 Umm so.
01:19:12.703 --> 01:19:15.340 I thought you meant calling filter by active on the query
01:19:15.340 --> 01:19:16.523 that you couldn't do that.
01:19:16.973 --> 01:19:20.583 I was like, uh, yeah, OK.
01:19:18.383 --> 01:19:18.613 Yeah.
01:19:18.623 --> 01:19:19.653 No, you absolutely can.
01:19:19.723 --> 01:19:19.883 Yeah.
01:19:20.573 --> 01:19:24.823 Umm, but and probably yeah.
01:19:24.873 --> 01:19:30.973 Anyway, so yeah, and yeah, cool.
01:19:25.203 --> 01:19:26.013 Happy Friday.
01:19:32.863 --> 01:19:36.103 And then also on the inner active call you would use.
01:19:36.113 --> 01:19:36.353 Why?
01:19:36.363 --> 01:19:39.818 Because you've already got excess spent for the outer part
01:19:39.493 --> 01:19:42.833 Yeah, it's relatively smart about it, but yeah.
01:19:39.783 --> 01:19:40.003 Yeah.
01:19:39.818 --> 01:19:41.223 and the order resending.
01:19:43.743 --> 01:19:47.654 Yeah, I always do that, but it can follow it pretty deep, can't
01:19:43.823 --> 01:19:44.003 Yeah.
01:19:47.654 --> 01:19:48.143 it like?
01:19:47.733 --> 01:19:48.163 Yeah.
01:19:48.213 --> 01:19:48.983 Yeah, it can.
01:19:48.993 --> 01:19:53.626 It it outside of actual expression tree building which
01:19:53.626 --> 01:19:56.743 is not something anybody's gonna do.
01:19:58.713 --> 01:20:01.243 They the same names, all it's doing is it?
01:20:01.253 --> 01:20:04.381 It takes the the nearest one in scope, basically, but that
01:20:04.381 --> 01:20:07.668 unfortunately means is that if I needed to reference anything
01:20:07.668 --> 01:20:10.955 inside this where like if I was using X on all of these and I
01:20:10.955 --> 01:20:14.083 need it to reference something about this X inside of this
01:20:14.083 --> 01:20:17.211 scope, I couldn't, but having them be different names as I
01:20:15.953 --> 01:20:16.353 Right.
01:20:17.211 --> 01:20:20.604 could do alright active equals X dot active for whatever reason
01:20:20.604 --> 01:20:23.043 if I wanted to do something stupid like that.
01:20:23.053 --> 01:20:26.843 But, umm, exactly.
01:20:24.203 --> 01:20:27.533 And the readability goes way down to if you choose the same.
01:20:26.853 --> 01:20:27.213 Yeah.
01:20:26.893 --> 01:20:27.443 Yeah.
01:20:27.263 --> 01:20:28.843 Yeah, so.
01:20:27.833 --> 01:20:32.053 Yeah, that that's one of the things I'm gonna be a real hard
01:20:32.053 --> 01:20:36.342 asks about on PR's is follow, like, like give your individual
01:20:36.342 --> 01:20:40.424 scopes their own letters to go through, and generally it's
01:20:39.343 --> 01:20:39.543 Yeah.
01:20:40.424 --> 01:20:41.323 gonna be XYZ.
01:20:41.513 --> 01:20:44.891 And if you need beyond ZA, is that a query that should be
01:20:44.891 --> 01:20:48.443 broken up, or B just the letter next letter need to be A and
01:20:48.443 --> 01:20:51.763 start with ABC D on down the line for what you're doing.
01:20:51.843 --> 01:20:54.775 So if I see, usually you're not gonna go more than like two or
01:20:54.775 --> 01:20:56.683 three levels deep in this kind of thing.
01:20:56.693 --> 01:20:59.649 But there are like extreme scenarios where some super
01:20:59.649 --> 01:21:03.263 complicated things going on, but it's just the only way to do it.
01:21:03.453 --> 01:21:06.474 So it's OK if that's what you gotta do, but at that point
01:21:03.693 --> 01:21:03.943 Yeah.
01:21:06.474 --> 01:21:09.860 you're probably gonna be asking for help from Brendan or myself,
01:21:09.860 --> 01:21:11.423 and we'll walk you through it.
01:21:10.293 --> 01:21:10.473 Yep.
01:21:10.943 --> 01:21:11.203 Yeah.
01:21:13.353 --> 01:21:16.878 So and then as a as a final teaser, and again, everyone's
01:21:16.878 --> 01:21:20.646 free to drop if you don't care, but I've been working on some
01:21:20.646 --> 01:21:24.232 entity framework key stuff in Phoenix recently that's been
01:21:24.232 --> 01:21:25.873 pretty neat, but it's also.
01:21:25.633 --> 01:21:28.233 Wow. Can we?
01:21:27.263 --> 01:21:28.183 And see if core.
01:21:28.153 --> 01:21:28.963 Horrifying.
01:21:28.973 --> 01:21:30.493 Yeah, this is the F core, but it's also.
01:21:29.403 --> 01:21:30.473 Now, now hold up.
01:21:30.483 --> 01:21:34.543 Hold up before we move on from the other screen.
01:21:34.703 --> 01:21:35.123 Oh, sure, yeah.
01:21:35.593 --> 01:21:39.433 JG to clarify here he's got where?
01:21:40.093 --> 01:21:42.203 X OHH OK I thought so.
01:21:42.213 --> 01:21:42.903 Why there?
01:21:43.233 --> 01:21:46.423 But I thought all three of them were Y, but we have two Y.
01:21:43.493 --> 01:21:44.453 There's a Y right here, yeah.
01:21:46.433 --> 01:21:49.673 Do you want the two Y's to be separated in one be Z?
01:21:47.393 --> 01:21:51.273 So the reason so these two guys are separate, yeah.
01:21:48.313 --> 01:21:50.903 The those two wives are at the same level.
01:21:51.343 --> 01:21:53.773 So look at if you notice it's a little bit hard to tell.
01:21:53.843 --> 01:21:57.632 The parentheses here are containing both of the why's,
01:21:56.633 --> 01:21:57.073 Gotcha.
01:21:57.632 --> 01:22:00.663 but this why is inside its own parentheses.
01:22:00.673 --> 01:22:04.702 This why is inside its own parentheses, and if I were doing
01:22:04.702 --> 01:22:08.798 something inside of these where I had like another thing, or
01:22:08.798 --> 01:22:12.290 maybe let me look and see umm uh, do I have any eye
01:22:09.683 --> 01:22:14.545 You could do a account off the bid and do account contacts I
01:22:12.290 --> 01:22:13.633 collections in here?
01:22:12.423 --> 01:22:15.853 It's OK, I'm understanding now.
01:22:14.545 --> 01:22:15.023 think.
01:22:15.863 --> 01:22:18.263 It's by level, not by filter.
01:22:17.653 --> 01:22:18.613 Right, exactly.
01:22:17.913 --> 01:22:18.183 Yeah.
01:22:18.623 --> 01:22:20.083 Yeah, they don't all need to be separate.
01:22:20.093 --> 01:22:23.588 It's just that you can't nest X's inside of's inside of you
01:22:23.588 --> 01:22:23.763 is.
01:22:23.773 --> 01:22:24.023 Etcetera.
01:22:24.753 --> 01:22:25.363 Umm.
01:22:24.833 --> 01:22:25.053 Yeah.
01:22:25.753 --> 01:22:28.333 So each each scope each.
01:22:26.193 --> 01:22:27.293 OK, understood.
01:22:28.343 --> 01:22:31.033 Each scope should have its own name if that makes sense.
01:22:32.723 --> 01:22:33.743 Yeah. OK.
01:22:34.863 --> 01:22:37.717 Yeah, we've, we've seen that on the front end like rezuan and
01:22:37.717 --> 01:22:38.223 then Rez 2.
01:22:39.653 --> 01:22:40.083 Yeah.
01:22:40.093 --> 01:22:42.233 So that that's exactly right.
01:22:42.243 --> 01:22:46.125 When you've got like 4 promises nested and it goes R1R2R3R4 and
01:22:42.493 --> 01:22:42.783 Umm.
01:22:46.125 --> 01:22:48.733 then like on the catches, it's got reason.
01:22:48.743 --> 01:22:49.593 One reason?
01:22:49.603 --> 01:22:49.993 Two reason?
01:22:50.003 --> 01:22:53.388 Three reason 4 that's to help keep those names separate and
01:22:53.388 --> 01:22:56.716 very clear about which one you're referring to so that you
01:22:55.243 --> 01:22:55.493 Umm.
01:22:56.716 --> 01:22:58.973 can't mix them up by accident on there.
01:22:59.493 --> 01:23:03.932 And just like with the front end and the back end, in both cases
01:23:03.932 --> 01:23:06.323 they are actually perfectly valid.
01:23:06.393 --> 01:23:11.578 You might get warnings, but it will compile on both of those
01:23:11.578 --> 01:23:12.173 pieces.
01:23:12.183 --> 01:23:16.189 It'll just be confusing to the next guy who comes in and reads
01:23:16.189 --> 01:23:20.323 it, including yourself later on, so make sure you don't do that.
01:23:18.253 --> 01:23:18.413 Yeah.
01:23:21.703 --> 01:23:22.423 Alright, cool.
01:23:21.893 --> 01:23:22.073 Yeah.
01:23:23.883 --> 01:23:24.373 Umm.
01:23:24.063 --> 01:23:24.733 Let's move on.
01:23:24.883 --> 01:23:25.193 Thank you.