EF Core encoding with Firebird 2.5

Viewed 845

I am migrating a legacy system made in Delphi + FireDac to C# + EF. As it is a legacy system, there is already a database with many records (Many records without encoding information).

When I get records that contain special characters using C# + EF, the characters are not displayed correctly.

How can I fix this problem?

C#

enter image description here

Delphi

enter image description here

MainWindow.xaml.cs - ButtonClick

private void Button_Click(object sender, RoutedEventArgs e)
{
    string appPath = AppContext.BaseDirectory;
    string connectionString = $"database=localhost/3050:{appPath}\\database\\test.fdb;user=sysdba;password=masterkey";          
    using (AppDbContext con = new AppDbContext(connectionString))
    {
        Product p = con.Products.First();
        lblText.Text = p.Name;                
    }
}

AppDbContext.cs

public class AppDbContext : DbContext
{
    private readonly string _connectionString;
    public DbSet<Product> Products { get; set; }

    public AppDbContext(string connectionString)
    {
        _connectionString = connectionString;
    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);

        optionsBuilder.UseFirebird(_connectionString);
    }
}

Product.cs

[Table("PRODUCTS")]
public class Product
{
    [Column("ID")]
    public int Id { get; set; }
    [Column("NAME")]
    public string Name { get; set; }
}

Complete C# project code

1 Answers

For firebird, most of the times, issues with special characters can be handled with the use of CharSet UTF-8. Within connectionString, you may need to include charset=utf8.

Added update:

Thanks to @Felipe Godinho for the feedback, it seems charset=win1252 has been found to be another valuable option of CharSet that is worth to try when handling legacy database system that is running on Firebird.

Related