Entity framework EntityFramework 4.1 DbContext选择添加带其他字符的强制转换列

Entity framework EntityFramework 4.1 DbContext选择添加带其他字符的强制转换列,entity-framework,entity-framework-4.1,dbcontext,Entity Framework,Entity Framework 4.1,Dbcontext,我正在从dbcontext执行标准GetAll(): DbContext.Set<T>() DbContext.Set() 然而,我从甲骨文那里得到了一个奇怪的信息: {“ORA-00904:\“Extent1\”\“Sub\u Object\u ID\”:无效标识符“} 如果我查看生成的sql(通过查看查询变量),我会看到在最后添加了一些变量作为强制转换 "Extent1"."SomeEntity_ID", <--

我正在从dbcontext执行标准GetAll():

 DbContext.Set<T>()
DbContext.Set()
然而,我从甲骨文那里得到了一个奇怪的信息:

{“ORA-00904:\“Extent1\”\“Sub\u Object\u ID\”:无效标识符“}

如果我查看生成的sql(通过查看查询变量),我会看到在最后添加了一些变量作为强制转换

"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"

“Extent1”、“SomeEntity\u ID”这只是配置外键的问题。我仍然不理解这种默认行为的意图(为每个外文添加一组select列,并附加“1”)

但是声明外键可以解决这个问题

通过fluent API:

modelBuilder.Entity<FirmPerson>()
    .HasRequired(f => f.Firm)
    .WithMany(p => p.FirmPerson)
    .HasForeignKey(f => f.FirmID);
modelBuilder.Entity<FirmPerson>()
    .HasRequired(f => f.Firm)
    .WithMany(p => p.FirmPerson)
    .HasForeignKey(f => f.FirmID);
    public int FirmID { get; set; }

    [ForeignKey("FirmID")]
    public virtual Firm Foo { get; set; }