在构建Linq-to-Sql代码时强制实体框架不生成NCLOB(模型优先) [英] Forcing Entity Framework to not generate NCLOB's when building Linq-to-Sql Code (Model First)
问题描述
我有一个具有可为null的int属性的类,出于过滤原因,我需要将其转换为字符串以进行一些比较.我已经安装了EF 6.1.2,因此使用.ToString()可以解决该问题.
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"));
在检查正在执行的实际SQL时,该数字正被CAST转换为NCLOB类型,从而导致以下错误:
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:数据类型不一致:预期的NCHAR-得到了NCLOB
ORA-00932: inconsistent datatypes: expected NCHAR - got NCLOB
据我所读,这是因为在这种情况下,实体不知道潜在的最大大小,因此它默认为最大选项.我知道,使用字符串属性,我可以表示最大大小来提供帮助.在将该属性保留为int值以防止使用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?
其他一些注释:
- 我在Oracle系统上,因此SqlFunctions.StringConvert退出了.
- 我使用的是Odp.net 12.x版(与
- .Where()子句被添加到AsQueryable()中,所以我无法在内存中做任何事情.
推荐答案
我对Oracle( Oracle 11.2.02和Oracle.ManagedDataAccess.12.2.1100 )和实体框架( EntityFramework.6.1.3 ).
I have the same problem with Oracle (Oracle 11.2.02 and Oracle.ManagedDataAccess.12.2.1100) and Entity Framework (EntityFramework.6.1.3).
此内部Linq代码(属性"Id"是整数):
This inside Linq code (the property "Id" is integer):
Material.Id.ToString()
生成此SQL:
问题是 TO_NCLOB ,应该是 TO_NCHAR
解决方案
JonathanPeel评论
安装包EntityFramework.Functions
这篇关于在构建Linq-to-Sql代码时强制实体框架不生成NCLOB(模型优先)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!