带有Firebird 2.5的EF Core编码 [英] EF Core encoding with Firebird 2.5
问题描述
我正在将用Delphi + FireDac制造的旧系统迁移到C#+ EF.由于它是旧系统,因此已经有一个包含许多记录的数据库(许多记录没有编码信息).
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).
当我使用C#+ EF获取包含特殊字符的记录时,这些字符无法正确显示.
When I get records that contain special characters using C# + EF, the characters are not displayed correctly.
如何解决此问题?
C#
德尔福
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; }
}
推荐答案
对于Firebird,大多数情况下,可以使用CharSet UTF-8处理特殊字符的问题.在 connectionString
中,您可能需要包含 charset = utf8
.
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
.
添加了更新:
感谢@Felipe Godinho的反馈,似乎已经发现 charset = win1252
是CharSet的另一个有价值的选择,当处理运行在Firebird上的旧数据库系统时值得尝试.
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.
这篇关于带有Firebird 2.5的EF Core编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!