I have a class with a nullable int property that that for filtering reasons, I need to convert to a string to do some comparisons. I have EF 6.1.2 installed, so using a .ToString() will work for that.
queryableData = queryableData.Where(a =>
a.PropName.HasValue && a.PropName.Value.ToString().Contains("8675309"));
When examining the actual SQL being executed, the number is being CAST into an NCLOB type, which is resulting in the following error:
ORA-00932: inconsistent datatypes: expected NCHAR - got NCLOB
From what I've read, this is because Entity is unaware of the potential max size in this case, so it defaults to the largest option. I know with a string property that I would be able to denote a max size to help. Is there anything that I can do while keeping the property as an int to prevent the NCLOB's from being used? Or a way to use them while preventing this exception?
Some other notes:
I have the same problem with Oracle (Oracle 11.2.02 and Oracle.ManagedDataAccess.12.2.1100) and Entity Framework (EntityFramework.6.1.3).
This inside Linq code (the property "Id" is integer):
Material.Id.ToString()
Generates this SQL:
(CASE WHEN ("Extent3"."Material_Id" IS NULL) THEN N'' ELSE TO_NCLOB("Extent3"."Material_Id") END)
And the problem is TO_NCLOB, it should be TO_NCHAR
Solution
JonathanPeel comment
Install-Package EntityFramework.Functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With