ODP.Net Managed Driver - ORA-12704: character set mismatch in generated code

╄→гoц情女王★ 提交于 2019-11-29 07:24:31

I never did find the proper solution to this, however I did find a workaround that works well.

I created an Interceptor class NVarcharInterceptor implementing IDbCommandInterceptor, and overrode all of the ..Executing(..) methods to contain the following code:

if (command != null && !string.IsNullOrWhiteSpace(command.CommandText))
    command.CommandText = command.CommandText.Replace("N''", "''");   

This effectively removes any of the unwanted NVarchar references, from any command being executed on my DbContext.

To add the interceptor, I added the following code to by DBConfiguration class:

this.AddInterceptor(new NVarcharInterceptor());

Also you can create custom function for strings concatenation, and call it in LINQ instead of direct string concatenation.

For example: Create database function.

create or replace FUNCTION CONCAT2
(
  PARAM1 IN VARCHAR2 
, PARAM2 IN VARCHAR2 
) RETURN VARCHAR2 AS 
BEGIN
  RETURN PARAM1 || PARAM2;
END CONCAT2;

Add it to your model.I use database first approach, so I just had to update model. Map function in code:

using System;
using System.Data.Entity;

public static class DbFunctions
{
    [DbFunction("Model.Store", "CONCAT2")]
    public static string Concat(string arg1, string arg2)
    {
        return String.Concat(arg1, arg2);
    }
}

And use it in yours LINQ queries:

from c in CUSTOMER.AsNoTracking()
where c.ACCOUNT.Contains("DE")
   && c.DELETED == "N"
orderby DbFunctions.Concat(c.FORENAME, c.SURNAME)
select new { c.ACCOUNT, c.FORENAME, c.SURNAME})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!