【发布时间】:2014-03-20 14:34:18
【问题描述】:
我通过Oracle.ManagedDataAccess.Client 使用面向Oracle 11g 数据库的EF5 和.NET 4.5。我设置了一张小桌子来测试它的工作原理。
现在这是一个奇怪的事实,在搜索网络或本网站时均未显示任何结果。在每个查询中,我都有最后一列,例如 "Extent1"."Text_TextID" !!!这显然使 Oracle 抛出错误Invalid identifier,因为我没有具有此类名称的列,也没有数据库中的另一个对象。
无论我有多少表/列以及如何命名它们,都会发生这种情况(如果我有多个表,查询中都会有这个额外的列)。
有人知道为什么会这样吗??
示例代码如下:
//POCO class and mapping
[Table("LO_USERS")]
public class User
{
[Key]
[Column("USER_ID")]
public int UserID { get; set; }
}
//define the context
public class TestContext : DbContext
{
public TestContext():base("OracleConn")
{
}
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//replace the annoying dbo schema name. Note: even if I remove this, I still get the extra column in the query
modelBuilder.Entity<User>().ToTable("LO_USERS", "TEST_SCHEMA");
}
//create a new user
using (var db = new TestContext())
{
var user = new User();
db.Users.Add(user);
//here I set a breakpoint
db.SaveChanges();
}
VS2012 在断点处显示的查询:
SELECT
1 AS "C1",
CAST( "Extent1"."USER_ID" AS number(10,0)) AS "C2",
"Extent1"."Text_TextID" AS "Text_TextID"
FROM "TEST_SCHEMA"."LO_USERS" "Extent1"
编辑:
EF6 和 DotConnect 也是如此。
【问题讨论】:
标签: oracle oracle11g entity-framework-5