Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instruct LINQ to Entities to Generate Oracle Compatible SQL

I have a linq to entities query (EF 4.3)

var query = from item in db.TableTest
            select item.VAL;

which translates to this SQL statement

SELECT
"Extent1"."VAL" AS "VAL"
FROM "dbo"."TEST_TABLE" "Extent1"

The database is Oracle.

When I execute the query I get the message that the datatable does not exist. The problem is the ("dbo") part. If i remove it and execute this query directly (not through LINQ but through an oracleconnection etc)

SELECT
"Extent1"."VAL" AS "VAL"
FROM "TEST_TABLE" "Extent1"

then everything is ok. I get values back.

How can I instruct Linq To Entities to output Oracle compatible SQL?

like image 323
Thanasis Ioannidis Avatar asked Dec 14 '25 16:12

Thanasis Ioannidis


2 Answers

Assuming you have an entity model, make sure you correctly set the DDL generation template.

Also, you can remove the dbo for the database schema name to match your actual DB.

enter image description here

like image 141
ken2k Avatar answered Dec 16 '25 11:12

ken2k


Shortly after asking, i found a way to solve my problem

I had this POCO class

[Table("TEST_TABLE")]
public class MyEntity
{
    [Key, Column("VAL")]
    public string key_valye { get; set; }
}

The generated sql injected the "dbo". When i changed the table attribute to

 [Table("TEST_TABLE", Schema="ATT")]

This generated the "ATT"."TEST_TABLE" instead, which was actually the correct sql.

like image 23
Thanasis Ioannidis Avatar answered Dec 16 '25 12:12

Thanasis Ioannidis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!