McArthey
McArthey

Reputation: 1646

Invalid query generated for Oracle database

I am using Entity Framework 5 and code first for the database modeling and mapping. When I attempt to execute the query via an API call I receive an error that states ORA-00942: table or view does not exist. Reviewing the query it appears to be in a format that is not typical for Oracle queries.

My .config connection string is

<connectionStrings>
  <add name="Entities" connectionString="Data Source=development;
                                         User ID=user;Password=password"
                       providerName="Oracle.DataAccess.Client" />
</connectionStrings>

Within the OnModelCreating() I am mapping as follows

modelBuilder.Entity<Job>().ToTable("Table1", "schema");

The query that is being generated that I can see in the debugger does not execute via a copy/paste to Oracle.

SELECT "Extent1"."ColumnName" AS "ColumnName"
FROM "schema"."Table1" "Extent1"

I would have thought that the fact I am using the Oracle.DataAccess.Client provider that the query would be generated appropriately. How do I convince EF5 that it should generate the query in a specific fashion to be compatible with Oracle?

Upvotes: 0

Views: 242

Answers (1)

sstan
sstan

Reputation: 36473

The query itself is valid, it's just that because the identifier names are wrapped in double quotes, then the names become case sensitive.

As you probably didn't define a specific casing for your table and schema name, you should probably just upper case it (default Oracle casing) when creating the mapping in EF:

modelBuilder.Entity<Job>().ToTable("TABLE1", "SCHEMA"); // upper case.

Upvotes: 1

Related Questions