Forcing Entity Framework not to generate NCLOBs when building Linq-to-Sql code (model first)
I have a class with a nullable int property that for filtering reasons I need to convert to string in order to do some comparisons. I have EF 6.1.2 installed, so .ToString () will be used for this.
queryableData = queryableData.Where(a =>
a.PropName.HasValue && a.PropName.Value.ToString().Contains("8675309"));
When parsing the actual SQL being executed, the number is CAST to type NCLOB, resulting in the following error:
ORA-00932: inconsistent data types: NCHAR expected - NCLOB received
From what I read, this is because in this case the Entity is unaware of the possible maximum size, so the largest option is used by default. I know with a string property that I can specify a maximum size to help. Is there anything I can do by storing the property as an int to prevent the NCLOB from being used? Or a way to use them while preventing this exception?
Some other notes:
- I am on an Oracle system, so SqlFunctions.StringConvert is missing.
- I'm on Odp.net version 12.x (linked to this post ).
- EF is a Model-First approach.
- The .Where () clause is appended to AsQueryable () so I can't do anything in memory.
source to share
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 code inside Linq (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 must be TO_NCHAR
Solution
comment JonathanPeel
Install-Package EntityFramework.Functions
source to share