I'm using Entity Framework 5 and I want to select data from Oracle 10g database.
Problem is that the database table is huge and the query generated by Entity Framework is ineffective. I want to get rid of those CAST( [column] AS [type] )
. Is there any setting to turn them off?
C# code:
var context = new APPDB();
var q = context.APP_TABLE.Where(i => i.ID == 123);
// This is how I did get the generated SQL query
var str = ((System.Data.Objects.ObjectQuery) q ).ToTraceString();
The generated query:
SELECT
CAST( "Extent1"."ID" AS number(10,0)) AS "C1",
"Extent1"."DESCRIPTION" AS "DESCRIPTION"
FROM "APP"."APP_TABLE" "Extent1"
WHERE (123 = ( CAST( "Extent1"."ID" AS number(10,0))))
What I want is the code to generate better performing query:
SELECT
"Extent1"."ID" AS "C1",
"Extent1"."DESCRIPTION" AS "DESCRIPTION"
FROM "APP"."APP_TABLE" "Extent1"
WHERE
"Extent1"."ID" = 123
Better later than never )
If you are using code first and manual mapping classes, use HasColumnType("INT") configuration for int properties.
For example:
var entity = builder.Entity<APP_TABLE>();
entity
.HasKey(x => x.ID)
.ToTable("APP_TABLE", "SCHEMA");
entity
.Property(x => x.ID)
.HasColumnType("INT");
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