Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

EF Core query to Oracle with non unicode column throwing "ORA-12704: character set mismatch"

user-k39muJul 25 2023

I have a problem in EF Core with unicode.

I have this code in DataContext

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);

    #region Province

    var provinceEntity = modelBuilder.Entity<Province>();
    provinceEntity.ToTable("GTPROVINCES");

    #region properties

    provinceEntity.Property(table => table.ProvinceId).HasColumnName("PROVINCEID");
    provinceEntity.Property(table => table.Name).HasColumnName("NAME").IsUnicode(false);

    #endregion properties

    #region keys

    provinceEntity.HasKey(e => new { e.ProvinceId });
    #endregion keys

    #endregion Province
}

And I have an ApiController with this code:

[HttpGet]
public async Task<IActionResult> Index()
{
    string test1 = "test1";
    string test2 = "test2";

    var lista = unitOfWork.ProvinceRepository.Fetch().Select(x => new
        {
            name = x.Name == test1 ? test1 : test2
        });
    System.Diagnostics.Debug.WriteLine(lista.ToQueryString());
    lista.ToList();

    return new EmptyResult();
}

When ToList() is run, I get this error:

ORA-12704: character set mismatch

The problem is that the query launched to database is

DECLARE 
l_sql     varchar2(32767);
l_cur     pls_integer;
l_execute pls_integer;

BEGIN
l_cur := dbms_sql.open_cursor;
l_sql := 'SELECT CASE
    WHEN "g"."NAME" = :test1_0 THEN :test1_0
    ELSE :test2_1
END "name"
FROM "GTPROVINCES" "g"';
dbms_sql.parse(l_cur, l_sql, dbms_sql.native);
dbms_sql.bind_variable(l_cur, ':test1_0', 'test1');
dbms_sql.bind_variable(l_cur, ':test2_1', N'test2');
l_execute:= dbms_sql.execute(l_cur);
dbms_sql.return_result(l_cur);
END;

And it is mixing test1 in ansi characters and test2 in unicode characters.

Could youhelp me, please?

I expected all literals was in ansi characters.

This post has been answered by Alex Keh-Oracle on Nov 15 2023
Jump to Answer
Comments
Post Details
Added on Jul 25 2023
2 comments
135 views