asp.net-mvc-3 – 如何配置DbContext以使用Oracle ODP.Net和EF CodeFirst?

我正在尝试使用ODP.net在Oracle下使用EF CodeFirst.这是我的DbContext类:
public class MyCEContext : DbContext {

    public DbSet<Person> Persons { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        modelBuilder.Entity<Person>().ToTable("PERSONS","myce");

    }

    public MyCEContext() : 
        base(new OracleConnection(
            "Data Source=cebd; User ID=myce; Password=****;"),true) {}

}

问题是,当我尝试做这样的事情时:

MyCEContext context = new MyCEContext();
Person p = context.Persons.Find(1);

我得到这个内心的错误

{"ORA-00942: table or view does not exist"}

表格存在.

我究竟做错了什么?

解决方法

正如Nick在他的回答中所写的那样,问题与生成查询的引用和大小写有关,但与表的名称有关,但与模式的名称有关:
SELECT * 
FROM "myce"."PERSONS" "Extent1"

所以解决方案非常简单,只是大写用户ID和模式名称

modelBuilder.Entity<Person>().ToTable("PERSONS","MYCE");

通常,所有都必须是大写的:表,模式和字段的名称.但最好使用Column属性注释每个映射属性,而不是使用大写属性名称

[Column("FirsT_NAME")]
    public string FirstName { get; set; }

因此,名称将更容易在数据库和类中读取.

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...