1 00:00:00,470 --> 00:00:05,240 Our list query is currently retrieving all of the comic books from the database. 2 00:00:05,240 --> 00:00:08,900 A typical requirement is to retrieve a list of entities that match 3 00:00:08,900 --> 00:00:10,540 a set of criteria. 4 00:00:10,540 --> 00:00:12,840 This is known as filtering. 5 00:00:12,840 --> 00:00:16,742 We can filter the results of a query by using the where link operator. 6 00:00:20,321 --> 00:00:28,501 .Where(cb => cb.IssueNumber == 1). 7 00:00:28,501 --> 00:00:33,878 This query will return all of the comic books that have an issue number of 1. 8 00:00:33,878 --> 00:00:36,157 Before we test our query, let's use a for 9 00:00:36,157 --> 00:00:40,340 each loop to write each comic book's display text property to the console. 10 00:00:42,570 --> 00:00:47,469 For each var comicBook in 11 00:00:47,469 --> 00:00:54,004 comicBooks console.WriteLine 12 00:00:54,004 --> 00:00:59,150 comicBook DisplayText. 13 00:00:59,150 --> 00:01:01,492 Let's also include the comic book series property. 14 00:01:04,256 --> 00:01:10,336 .include cb goes to cb.series. 15 00:01:11,936 --> 00:01:16,226 And lastly add an additional Console.WriteLine method call in order to 16 00:01:16,226 --> 00:01:20,529 add a blank line between the list of comic books and the comic book count. 17 00:01:24,955 --> 00:01:26,752 Console.WriteLine. 18 00:01:30,940 --> 00:01:34,980 Our query returned a total of three comic books. 19 00:01:34,980 --> 00:01:38,605 And the generated query now contains a WHERE clause. 20 00:01:46,789 --> 00:01:51,725 We can add multiple calls to the where 21 00:01:51,725 --> 00:01:56,661 method in order to filter by more than 22 00:01:56,661 --> 00:02:01,120 one expression .where cb goes to 23 00:02:01,120 --> 00:02:07,830 cb.Series.Title = The Amazing Spider-Man. 24 00:02:07,830 --> 00:02:12,614 This query will return all comic books whose issue number is one and 25 00:02:12,614 --> 00:02:15,793 whose series title is The Amazing Spider-Man. 26 00:02:15,793 --> 00:02:17,922 An alternative way to write this query, 27 00:02:17,922 --> 00:02:22,130 is to combine the filtering expressions into a single conditional statement. 28 00:02:24,860 --> 00:02:29,224 If we wanted to get all the comic books whose issue number is one or who's 29 00:02:29,224 --> 00:02:33,736 series title is The Amazing Spider-Man we can change the conditional and 30 00:02:33,736 --> 00:02:35,646 operator to a conditional or. 31 00:02:40,152 --> 00:02:43,270 Our query now returns a total of five comic books. 32 00:02:47,000 --> 00:02:52,135 And the query's WHERE clause now contains two conditions separated by the OR 33 00:02:52,135 --> 00:02:52,851 keyword. 34 00:02:57,458 --> 00:02:59,117 Using the equality operator, 35 00:02:59,117 --> 00:03:03,830 we'll require that the comic book series title match a provided string. 36 00:03:03,830 --> 00:03:07,774 If we want all of the comic books whose series titles contained the string man, 37 00:03:07,774 --> 00:03:10,359 we can switch to using the string contains method. 38 00:03:12,771 --> 00:03:19,267 Where cb goes to cb.series.Title.Contains. 39 00:03:24,407 --> 00:03:25,308 Man. 40 00:03:29,185 --> 00:03:32,156 Now, our query returns a total of 6 comic books. 41 00:03:35,532 --> 00:03:40,559 And the queries where clause is using the like operator with wildcards surrounding 42 00:03:40,559 --> 00:03:45,690 our search text, which is the SQL way of performing a contained search. 43 00:03:45,690 --> 00:03:49,780 In this query, our man's search text with a lowercase m 44 00:03:49,780 --> 00:03:54,010 matched column values containing man with an uppercase M. 45 00:03:54,010 --> 00:03:57,860 Generally speaking when using EF the casing of the string 46 00:03:57,860 --> 00:04:00,070 doesn't matter when filtering data. 47 00:04:00,070 --> 00:04:04,172 Though that behavior depends on how your database server is configured. 48 00:04:04,172 --> 00:04:08,760 By default SQL Server is configured to be case insensitive. 49 00:04:08,760 --> 00:04:12,100 Though it's possible to change this configuration. 50 00:04:12,100 --> 00:04:14,995 For more information on case sensitivity and EF and 51 00:04:14,995 --> 00:04:17,790 SQL Server, see the teacher's notes. 52 00:04:17,790 --> 00:04:21,880 After a short code challenge we'll see how we can order the results of our query.