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

后端 未结 2 530
盖世英雄少女心
盖世英雄少女心 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: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 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.

提交回复
热议问题