Skip to content

Commit e8c64e6

Browse files
authored
SQLite guidance for case insensitive filtering (#35853)
1 parent 5468978 commit e8c64e6

File tree

1 file changed

+11
-5
lines changed
  • aspnetcore/blazor/tutorials/movie-database-app

1 file changed

+11
-5
lines changed

aspnetcore/blazor/tutorials/movie-database-app/part-6.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,16 @@ Change the `QuickGrid` component's <xref:Microsoft.AspNetCore.Components.QuickGr
5858

5959
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.
6060

61-
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.
61+
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.
62+
63+
To adopt case-insensitive collation when using SQLite (<xref:Microsoft.EntityFrameworkCore.SqliteDbContextOptionsBuilderExtensions.UseSqlite%2A> is called in `Program.cs`), open the `Data/BlazorWebAppMoviesContext.cs` file. Inside the `BlazorWebAppMoviesContext` class, add the following code:
64+
65+
```csharp
66+
protected override void OnModelCreating(ModelBuilder modelBuilder)
67+
{
68+
modelBuilder.UseCollation("SQL_Latin1_General_CP1_CS_AS");
69+
}
70+
```
6271

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

@@ -143,10 +152,7 @@ Stop the app by closing the browser's window and pressing <kbd>Ctrl</kbd>+<kbd>C
143152
* [LINQ documentation](/dotnet/csharp/programming-guide/concepts/linq/)
144153
* [Write C# LINQ queries to query data (C# documentation)](/dotnet/csharp/programming-guide/concepts/linq/query-syntax-and-method-syntax-in-linq)
145154
* [Lambda Expression (C# documentation](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions)
146-
* Case insensitive SQLite queries
147-
* [How to use case-insensitive query with Sqlite provider? (`dotnet/efcore` #11414)](https://github.com/dotnet/efcore/issues/11414)
148-
* [How to make a SQLite column case insensitive (`dotnet/AspNetCore.Docs` #22314)](https://github.com/dotnet/AspNetCore.Docs/issues/22314)
149-
* [Collations and Case Sensitivity](/ef/core/miscellaneous/collations-and-case-sensitivity)
155+
* [Collations and Case Sensitivity](/ef/core/miscellaneous/collations-and-case-sensitivity)
150156

151157
## Legal
152158

0 commit comments

Comments
 (0)