Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion aspnetcore/blazor/tutorials/movie-database-app/part-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ Change the `QuickGrid` component's <xref:Microsoft.AspNetCore.Components.QuickGr

The `movie => movie.Title!.Contains(...)` code is a *lambda expression*. Lambdas are used in method-based LINQ queries as arguments to standard query operator methods such as the <xref:System.Linq.Queryable.Where%2A> or <xref:System.String.Contains%2A> methods. LINQ queries aren't executed when they're defined or when they're modified by calling a method, such as <xref:System.Linq.Queryable.Where%2A>, <xref:System.String.Contains%2A>, or <xref:System.Linq.Queryable.OrderBy%2A>. Rather, query execution is deferred. The evaluation of an expression is delayed until its realized value is iterated.

The <xref:System.Data.Objects.DataClasses.EntityCollection%601.Contains%2A> method is run on the database, not in the C# code. The case sensitivity of the query depends on the database and the collation. For SQL Server, <xref:System.String.Contains%2A> maps to [SQL `LIKE`](/sql/t-sql/language-elements/like-transact-sql), which is case insensitive. SQLite with default collation provides a mixture of case sensitive and case insensitive filtering, depending on the query. For information on making case insensitive SQLite queries, see the [Additional resources](#additional-resources) section of this article.
The <xref:System.Data.Objects.DataClasses.EntityCollection%601.Contains%2A> method is run on the database, not in the C# code. The case sensitivity of the query depends on the database and the collation. For SQL Server, <xref:System.String.Contains%2A> maps to [SQL `LIKE`](/sql/t-sql/language-elements/like-transact-sql), which is case insensitive. SQLite with default collation provides a mixture of case sensitive and case insensitive filtering, depending on the query. The remainder of this tutorial assumes case insensitive database collation. As a workaround for case sensitive database collation with SQLite, you can adjust the Linq query to lowercase the filtering operation by applying <xref:System.String.ToLower%2A> to the movie title and the filter variable. The following workaround is purely for demonstration purposes to match the instructions and examples in this tutorial:

```diff
- m => m.Title!.Contains(TitleFilter ?? string.Empty)
+ m => m.Title!.ToLower().Contains((TitleFilter ?? string.Empty).ToLower());
```

For information on the best practices to adopt case insensitive SQLite queries, see the [Additional resources](#additional-resources) section of this article.

Run the app and navigate to the movies `Index` page at `/movies`. The movies in the database load:

Expand Down
18 changes: 18 additions & 0 deletions aspnetcore/blazor/tutorials/movie-database-app/part-8.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ private IQueryable<Movie> FilteredMovies =>
context.Movie.Where(m => m.Title!.Contains(titleFilter));
```

> [!NOTE]
> If your database collation is case sensitive (for example, when using a SQLite database), you can lowercase the movie's title and `titleFilter` as a workaround:
>
> ```diff
> - m => m.Title!.Contains(titleFilter)
> + m => m.Title!.ToLower().Contains(titleFilter.ToLower())
> ```
>
> For information on the best practices to adopt case insensitive SQLite queries, see the [Additional resources](#additional-resources) section of this article.

Next, the component should bind the `titleFilter` field to an `<input>` element, so user input is stored in the `titleFilter` variable. Binding is achieved in Blazor with the `@bind` directive attribute.

Remove the HTML form from the component:
Expand Down Expand Up @@ -295,3 +305,11 @@ In the documentation website's sidebar navigation, articles are organized by sub

> [!div class="step-by-step"]
> [Previous: Add a new field](xref:blazor/tutorials/movie-database-app/part-7)

## Additional resources

Information and best practices to adopt case insensitive SQLite queries:

* [How to use case-insensitive query with Sqlite provider? (`dotnet/efcore` #11414)](https://github.com/dotnet/efcore/issues/11414)
* [How to make a SQLite column case insensitive (`dotnet/AspNetCore.Docs` #22314)](https://github.com/dotnet/AspNetCore.Docs/issues/22314)
* [Collations and Case Sensitivity](/ef/core/miscellaneous/collations-and-case-sensitivity)