Table Does Not Exist while using EF 6 and Oracle.ManagedDataAccess

后端 未结 2 507
盖世英雄少女心
盖世英雄少女心 2021-01-12 09:37

I am creating a MVC application using EF 6.0.0.0 and ODP.Net Oracle.ManagedDataAccess version 4.121.2.0 for the data access.

I

相关标签:
2条回答
  • 2021-01-12 10:12

    We had the same problem. What we found was a reference to the wrong database schema in the edmx file:

    <EntitySet Name="MyTable" EntityType="Self.MyTable" Schema="**wrongSchemaName**" store:Type="Tables" />
    

    By deleting the schema name our issue was resolved.

    <EntitySet Name="MyTable" EntityType="Self.MyTable" Schema="" store:Type="Tables" />
    
    0 讨论(0)
  • 2021-01-12 10:22

    The problem why the Data Table was not found, as suggested by DevilSuichiro in the comment, was due to the wrong Schema used. By default, EF 6 use dbo as default schema while my schema is not dbo. To make the model having default schema, an overriding for OnModelCreating event is needed:

    public class EmployeeContext : DbContext {
        public DbSet<Employee> Employees { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder) {
            modelBuilder.HasDefaultSchema("myschema");
        }
    }
    

    Also, thanks to Ivan Stoev for his suggestion to check the SQL generated by the EF.

    0 讨论(0)
提交回复
热议问题