甲骨文ODP.Net实体框架6 - 选择ORA-00955表视图 [英] Oracle ODP.Net With Entity Framework 6 - ORA-00955 on Select from Table View

查看:209
本文介绍了甲骨文ODP.Net实体框架6 - 选择ORA-00955表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了应用程序,先用ODP.Net和没有实体 - 伟大工程

I have created to apps, first with ODP.Net and without Entity - works great.

static void Main(string[] args)
{
    OracleConnection con = new OracleConnection();

    //using connection string attributes to connect to Oracle Database
    con.ConnectionString = "user id=****;password=****;data source=" +
        "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server.org.net)(PORT=1521))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=ora1)))";
    con.Open();
    Console.WriteLine("Connected to Oracle" + con.ServerVersion);

    OracleCommand command = con.CreateCommand();
    command.CommandText = "SELECT ITEM FROM TEST.ORDERS";

    OracleDataReader reader = command.ExecuteReader();

    while (reader.Read())
    {
        Console.WriteLine("\t{0}",
            reader[0]);
    }
    reader.Close();

    // Close and Dispose OracleConnection object
    con.Close();
    con.Dispose();
    Console.WriteLine("Disconnected");
    Console.ReadKey();
}



TEST.ORDERS是一个视图。

TEST.ORDERS is a View.

二程序正在使用ODP.Net和的EntityFramework和manaly创建DbSet类(于Npgsql.EntityFramework测试,并从Oracle作品的观点伟大的,完美的复制)。应用程序将返回错误:ORA-00955。
我注意到,当架构,以一个没有观点秩序的变化名称,节目名称相同创建我的表。
这是我DbSet的开始时:

Second program is using ODP.Net and EntityFramework and manaly created DbSet class (which was tested on Npgsql.EntityFramework and works great, perfect copy of the view from Oracle). The application returns error: ORA-00955. I noticed that when the change name of the "Schema" to one that does not have a view 'ORDER', the program creates my table with the same name. This is my begining of DbSet:

[Table("ORDERS", Schema = "TEST")]

这是可能的,这是错误的。但我不知道如何建立,将有机会获得这一观点的实体。用户有权只选择。我想要做只读操作。

It is possible that it is wrong. But I do not know how to build the entities that will have access to this view. The user has permission only to SELECT. I want do read-only operations.

推荐答案

实体框架提供的Oracle实施非常差,但也有一些办法如何使。这个工作

Oracle implementation of Entity framework provider is very poor but there are some ways how to make this working.


  1. 简单但烦人 - 使用NULL,或者自己的数据库初始化实现:

  1. Simple but annoying - using NULL or own database initializer implementation:

Database.SetInitializer(NULL);

class DatabaseInitializer : IDatabaseInitializer<DatabaseContext>
{
    public void InitializeDatabase(DatabaseContext context)
    {
        // your implementation
    }
}

Database.SetInitializer(new DatabaseInitializer());



设置初始化之前先访问你的数据库。

Set the initialized before first access to your database.


  1. 如果你想使用迁移创建你的意见,然后用包控制台添加迁移与忽略的变化,例如添加迁移初始-ignorechanges 。这将使EF忽略了DB模式和模型之间的不一致(因为它会检查从 ALL_TABLES 只表,而不是视图),所以它不会尝试创建表。有一个在甲骨文EF执行,如果在初始迁移为空,删除并重新创建了 __ MigrationHistory 表,这样的错误不是你最初的迁移必须containt至少一个表在添加之前查看迁移或者你需要事后添加表。

  1. If you want to use migrations create your views and then add migration with ignoring changes, for instance using package console add-migration initial -ignorechanges. This will make EF ignoring the inconsistencies between the DB schema and model (because it checks only tables from ALL_TABLES, not views) so it will not try to create table. There is a bug in Oracle EF implementation that if the initial migration is empty it drops and recreates the __MigrationHistory table so either your initial migration must containt at least one table before you add the view migration or you need to add a table afterwards.

这篇关于甲骨文ODP.Net实体框架6 - 选择ORA-00955表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆