-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Open
Open
Copy link
Milestone
Description
When setting modelBuilder.UseCollation("NOCASE");
in OnModelCreating()
then text columns do not get this collation.
Suggested as bug in StackOverflow.
Steps to reproduce
- Create a .NET7 console application
- Add the
Microsoft.EntityFrameworkCore.Sqlite
version 7.0.12 - Create the following
DbContext
and data model:
public class MyDbContext : DbContext
{
public DbSet<MyDbTable> MyTable { get; set; }
public string DbPath { get; }
public MyDbContext()
{
// Copied from "Getting Started with EF Core" https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
DbPath = Path.Join(path, "mydb.db");
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.UseCollation("NOCASE");
base.OnModelCreating(modelBuilder);
}
}
public class MyDbTable
{
public int Id { get; set; }
public string Title { get; set; }
}
- Run
Add-Migration Initial
to create the migration - Run `Update-Database" to apply the migration
- Check the
MyTable.Title
column in the database to see that it does not have theNOCASE
collation - Run
Update-Database -Migration:0
to reset the database - Run
Remove-Migration
- Replace
modelBuilder.UseCollation("NOCASE");
withmodelBuilder.Entity<MyDbTable>().Property(t => t.Title).HasColumnType("TEXT COLLATE NOCASE");
- Run
Add-Migration Initial
- Run
Update-Database
- Check the
MyTable.Title
column to see that you can set theNOCASE
individually
Provider and version information
EF Core version:
Database provider: Microsoft.EntityFrameworkCore.Sqlite 7.0.12
Target framework: .NET 7.0
Operating system: Windows 11 Pro 22H2 (22621.2428)
IDE: Visual Studio Professional 2022 17.7.5