Question

i'm doing a standard GetAll() from dbcontext:

 DbContext.Set<T>()

however i'm getting a weird message from oracle:

{"ORA-00904: \"Extent1\".\"Sub_Object_ID\": invalid identifier"}

if i look at generated sql (by looking at the query variable), i see that a few variables are added at the end as CASTS

"Extent1"."SomeEntity_ID",                            <-- correct
"Extent1"."SomeEnttiy2_ID",                           <-- correct
"Extent1"."Sub_Object",                               <-- correct

CAST( "Extent1"."SomeEntity_ID1" AS number(10,0)) AS "C3",  <-- "1" appended
CAST( "Extent1"."SomeEnttiy2_ID1" AS number(10,0)) AS "C4", <-- "1" appended
CAST( "Extent1"."Sub_Object_ID" AS number(10,0)) AS "C5",   <-- "_ID" appended
...
FROM "dbo"."MyEntity" "Extent1"

all the properties were correctly identified in the main portion of the select. however in the CAST portion, property names were appended with digits and _ID.. this is causing the select to fail..

looking at my entity, i have the properties specified once.. in this format:

    public Nullable<decimal> SomeEntity_ID { get; set; }

what's with the casts?

Was it helpful?

Solution

this was just a matter of configuring foreign keys. I still don't understand the intention of this default behavior (adding a set of select columns for every foreign with appended "1")..

but declaring foreign keys fixes it.

via fluent API:

modelBuilder.Entity<FirmPerson>()
    .HasRequired(f => f.Firm)
    .WithMany(p => p.FirmPerson)
    .HasForeignKey(f => f.FirmID);

or via attribute:

    public int FirmID { get; set; }

    [ForeignKey("FirmID")]
    public virtual Firm Foo { get; set; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top