سؤال

I am using EF5 and .NET 4.5 targeting an Oracle 11g database through Oracle.ManagedDataAccess.Client. I set up a small table to test and the how it works. Now here is a weird fact which shows no result on searching the web nor this site. On every query I have a last column like "Extent1"."Text_TextID"!!! This obviously makes Oracle to throw an error Invalid identifier as I have no column with such name nor another object in the database. This happens no matter how many tables/columns I have and no matter how I name them (if I have several tables all will have this extra column in the query).

Anybody has any idea why this happens??

Sample code below:

//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();
        } 

The query as showing by VS2012 at the breakpoint:

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"

Edit:

It is the same with EF6 and DotConnect.

هل كانت مفيدة؟

المحلول

I found it: the problem was I was referencing User class in another class as child object, like

public class Text 
{
    public virtual ICollection<User> Users { get; set; }

without specifying any foreign key column in user class and EF was trying to set one by its own. Once I removed the line above the extra column disappeared from the select statement.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top