c# - Entity Framework 6.1.3 and Oracle produces sql with Unicode on NonUnicode column -
i'm using entity framework 6.1.3 oracle manageddataaccess 12.1.022 , oracle.manageddataaccess.entityframework 12.1.022 (nuget packages)(fig 1). project database first , imports model .edmx
file running t4 code.
fig 1.
the database uses varchar2
columns , .edmx
file recognizes them nonunicode. (fig 2 & 3)
fig 3.
when running query, oracle error ora-12704: character set mismatch
. query:
var emp2 = db.employees .where(s => s.first_nm.toupper().startswith(term.toupper()) || s.last_nm.toupper().startswith(term.toupper())) .select(c => new { label = c.first_nm + " " + c.last_nm, value = c.first_nm + " " + c.last_nm });
using .totracestring()
can see sql being sent is:
select 1 "c1", ((((case when ("extent1"."first_nm" null) n'' /* unicode here null value */ else "extent1"."first_nm" end)||(' ')))||(case when ("extent1"."last_nm" null) n'' else "extent1"."last_nm" end)) "c2", ((((case when ("extent1"."first_nm" null) n'' else "extent1"."first_nm" end)||(' ')))||(case when ("extent1"."last_nm" null) n'' else "extent1"."last_nm" end)) "c3" "riskmgmt"."employee" "extent1" ((( nvl(instr(upper("extent1"."first_nm"), upper(:p__linq__0)), 0) ) = 1) or (( nvl(instr(upper("extent1"."last_nm"), upper(:p__linq__1)), 0) ) = 1)) /** parameters **/ p__linq__0[system.string] = j /** parameters **/ p__linq__1[system.string] = j
the n''
portion of select clause causes error. if remove n
, query work. i've found through searching issue in ef4 nothing currently. idea why happening , way fix produced sql not unicode?
i able fix issue splitting query 2 different pieces , adding .toarray()
@ end of first where
clause. wanted return json object solution.
db.employees .where(s => s.first_nm.toupper().startswith(term.toupper()) || s.last_nm.toupper().startswith(term.toupper())) .toarray();
then formating json object:
return json(matching.select(m => new { id = m.emplid, value = m.first_nm + " " + m.last_nm, label = string.concat(m.first_nm, " ", m.last_nm), }), jsonrequestbehavior.allowget);
Comments
Post a Comment