带有实体框架的Oracle Database 10g到.Net类型
本文关键字:10g Net 类型 Database Oracle 实体 框架 | 更新日期: 2023-09-27 17:59:06
我将EF5与此Oracle提供程序一起使用:
<DbProviderFactories>
<remove invariant="Oracle.DataAccess.Client" />
<add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
我有一个列名BSO_KEYI,类型为Number(10)。我试着在我的POCO中使用long类型。
生成了以下请求:
SELECT
"Limit1"."C1" AS "C1",
"Limit1"."C2" AS "C2",
"Limit1"."C3" AS "C3",
"Limit1"."C4" AS "C4",
"Limit1"."BSO_TYPEVC" AS "BSO_TYPEVC",
"Limit1"."C5" AS "C5",
"Limit1"."C6" AS "C6",
"Limit1"."BSO_TITLE_ALTERNATIVEVC" AS "BSO_TITLE_ALTERNATIVEVC",
"Limit1"."BSO_TITLE_BROADCASTVC" AS "BSO_TITLE_BROADCASTVC",
"Limit1"."BSO_TITLE_ORIGINALVC" AS "BSO_TITLE_ORIGINALVC",
"Limit1"."BSO_TITLE_PRESSVC" AS "BSO_TITLE_PRESSVC",
"Limit1"."BSO_APPROX_LENGTHVC" AS "BSO_APPROX_LENGTHVC",
"Limit1"."C7" AS "C7",
"Limit1"."LAST_MODIFICATION_DATEDT" AS "LAST_MODIFICATION_DATEDT",
"Limit1"."CREATION_DATEDT" AS "CREATION_DATEDT"
FROM ( SELECT
"Extent1"."BSO_TYPEVC" AS "BSO_TYPEVC",
"Extent1"."BSO_TITLE_ALTERNATIVEVC" AS "BSO_TITLE_ALTERNATIVEVC",
"Extent1"."BSO_TITLE_BROADCASTVC" AS "BSO_TITLE_BROADCASTVC",
"Extent1"."BSO_TITLE_ORIGINALVC" AS "BSO_TITLE_ORIGINALVC",
"Extent1"."BSO_TITLE_PRESSVC" AS "BSO_TITLE_PRESSVC",
"Extent1"."BSO_APPROX_LENGTHVC" AS "BSO_APPROX_LENGTHVC",
"Extent1"."LAST_MODIFICATION_DATEDT" AS "LAST_MODIFICATION_DATEDT",
"Extent1"."CREATION_DATEDT" AS "CREATION_DATEDT",
CAST( "Extent1"."BSO_KEYI" AS number(19,0)) AS "C1",
CAST( "Extent1"."BSO_TYPEI" AS number(19,0)) AS "C2",
CAST( "Extent1"."BSO_NUMERATION_BROADCASTI" AS number(19,0)) AS "C3",
CAST( "Extent1"."BSO_NUMERATION_MASTERI" AS number(19,0)) AS "C4",
CAST( "Extent1"."BSO_MASTER_KEYI" AS number(19,0)) AS "C5",
CAST( "Extent1"."BSO_MASTER_SCHEDULE_KEYI" AS number(19,0)) AS "C6",
CAST( "Extent1"."LAST_MODIFICATION_UIDI" AS number(19,0)) AS "C7"
FROM "Foo"."XO_BS_OBJECT" "Extent1"
WHERE (( CAST( "Extent1"."BSO_KEYI" AS number(19,0))) = :p__linq__0) AND (ROWNUM <= (2) )
) "Limit1"
在那之后,我尝试了int,并生成了以下请求
SELECT
"Limit1"."C1" AS "C1",
"Limit1"."C2" AS "C2",
"Limit1"."C3" AS "C3",
"Limit1"."C4" AS "C4",
"Limit1"."BSO_TYPEVC" AS "BSO_TYPEVC",
"Limit1"."C5" AS "C5",
"Limit1"."C6" AS "C6",
"Limit1"."BSO_TITLE_ALTERNATIVEVC" AS "BSO_TITLE_ALTERNATIVEVC",
"Limit1"."BSO_TITLE_BROADCASTVC" AS "BSO_TITLE_BROADCASTVC",
"Limit1"."BSO_TITLE_ORIGINALVC" AS "BSO_TITLE_ORIGINALVC",
"Limit1"."BSO_TITLE_PRESSVC" AS "BSO_TITLE_PRESSVC",
"Limit1"."BSO_APPROX_LENGTHVC" AS "BSO_APPROX_LENGTHVC",
"Limit1"."C7" AS "C7",
"Limit1"."LAST_MODIFICATION_DATEDT" AS "LAST_MODIFICATION_DATEDT",
"Limit1"."CREATION_DATEDT" AS "CREATION_DATEDT"
FROM ( SELECT
"Extent1"."BSO_TYPEVC" AS "BSO_TYPEVC",
"Extent1"."BSO_TITLE_ALTERNATIVEVC" AS "BSO_TITLE_ALTERNATIVEVC",
"Extent1"."BSO_TITLE_BROADCASTVC" AS "BSO_TITLE_BROADCASTVC",
"Extent1"."BSO_TITLE_ORIGINALVC" AS "BSO_TITLE_ORIGINALVC",
"Extent1"."BSO_TITLE_PRESSVC" AS "BSO_TITLE_PRESSVC",
"Extent1"."BSO_APPROX_LENGTHVC" AS "BSO_APPROX_LENGTHVC",
"Extent1"."LAST_MODIFICATION_DATEDT" AS "LAST_MODIFICATION_DATEDT",
"Extent1"."CREATION_DATEDT" AS "CREATION_DATEDT",
CAST( "Extent1"."BSO_KEYI" AS number(10,0)) AS "C1",
CAST( "Extent1"."BSO_TYPEI" AS number(19,0)) AS "C2",
CAST( "Extent1"."BSO_NUMERATION_BROADCASTI" AS number(19,0)) AS "C3",
CAST( "Extent1"."BSO_NUMERATION_MASTERI" AS number(19,0)) AS "C4",
CAST( "Extent1"."BSO_MASTER_KEYI" AS number(19,0)) AS "C5",
CAST( "Extent1"."BSO_MASTER_SCHEDULE_KEYI" AS number(19,0)) AS "C6",
CAST( "Extent1"."LAST_MODIFICATION_UIDI" AS number(19,0)) AS "C7"
FROM "Foo"."XO_BS_OBJECT" "Extent1"
WHERE (( CAST( "Extent1"."BSO_KEYI" AS number(10,0))) = :p__linq__0) AND (ROWNUM <= (2) )
) "Limit1"
正如您在type long中看到的那样,EF将列强制转换为NUMBER(19,0),而在int中,数据库NUMBER(10,0)中有一个相同类型的强制转换。强制转换是否破坏了该列的索引?有更好的.Net类型吗?
据我所知,数字(x,y)的自然映射应该是十进制(或浮点,双精度)。至于您的"cast忽略索引"问题,数据库应该足够聪明才能使用它。
最后我们切换到Devart提供程序,它的工作效果更好(相同的C#类型,但不生成强制转换)。我们从3秒到0.4秒。