Firebird Embedded and Entity Framework Highlight Special Characters

Introduction

Hello to all! I am new here, and I hope I do it the right way “Ask.”;) I found a very confusing problem, and I hope someone here can help me.

Overview

I have a very specific problem with EntityFramework.Firebird-Provider.

When I try to update an object property using EntityFramework, special characters (like ö, ü, ä and ß) are converted to dots. However, this only happens when I use the EmbeddedServer functionality for Firebird.

Playback Steps

Create a simple Firebird database with one table. Here is the DDL of my test pattern:

CREATE TABLE CUSTOMER ( ID INTEGER NOT NULL, NAME1 VARCHAR(50) COLLATE ISO8859_1, NAME2 VARCHAR(50) COLLATE ISO8859_1, STREET VARCHAR(50) COLLATE ISO8859_1, CONSTRAINT PK_CUSTOMER PRIMARY KEY (ID) ); 

Create a small C # test project and add NuGet-Packages packages

  • FirebirdSql.Data.FirebirdClient
  • EntityFramework.Firebird

After that you need to update EntityFramework! For this, I used version 6.1.3.

Add a simple Entity, TypeConfiguration, and DbContext object as follows:

 public class SimpleCustomer { public int Id { get; set; } public string Name1 { get; set; } public string Name2 { get; set; } public string Street { get; set; } } public class SimpleCustomerTypeConfiguration : EntityTypeConfiguration<SimpleCustomer> { public SimpleCustomerTypeConfiguration() { this.ToTable("CUSTOMER"); this.HasKey(e => e.Id); this.Property(e => e.Id).HasColumnName("ID").HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); this.Property(e => e.Name1).HasColumnName("NAME1"); this.Property(e => e.Name2).HasColumnName("NAME2"); this.Property(e => e.Street).HasColumnName("STREET"); } } public class FbContext : DbContext { public DbSet<SimpleCustomer> SimpleCustomers { get; set; } public FbContext(DbConnection connection) : base(connection, false) { Database.SetInitializer(new NullDatabaseInitializer<FbContext>()); } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new SimpleCustomerTypeConfiguration()); base.OnModelCreating(modelBuilder); } } 

When you are now trying to update a property like Street with a DbContext, for example:

 using (var connection = new FbConnection(@"User=SYSDBA; Password=masterkey; Database=TEST.FDB; CharSet=ISO8859_1; ServerType=1; Pooling=false;")) { connection.Open(); using (var context = new FbContext(connection)) { var writeCustomer = context.SimpleCustomers.Find(1); writeCustomer.Street = @"Schloßallee 34"; context.SaveChanges(); } } 

The street has been saved as Schlo.allee 34 in the database.

Additional Information

Here are some additional information that I managed to find out:

  • This only happens if you use the built-in Firebird server. (ServerType = 1)
  • Changing a CharSet or converting an encoding to something like Unicode or Windows1252 does not seem to change anything.
    • Except when you change Connection-CharSet to UTF8: then you get two points instead of one. Yaaay! \ O /
  • The update works fine when you use the classic SQL Update command, for example, for example:

     using (var connection = new FbConnection(@"User=SYSDBA; Password=masterkey; Database=TEST.FDB; CharSet=ISO8859_1; ServerType=1; Pooling=false;")) { connection.Open(); var command = connection.CreateCommand(); command.CommandText = @"UPDATE CUSTOMER SET STREET = @STREET WHERE ID = @ID"; command.Parameters.Add(new FbParameter("STREET", FbDbType.VarChar, 50) { Value = "Schloßallee 34" }); command.Parameters.Add(new FbParameter("ID", FbDbType.Integer) { Value = 1 }); command.ExecuteNonQuery(); } 
+5
source share

All Articles