Oracle ODP.Net with Entity Framework 6 - ORA-00955 to choose from the table

I created applications, first with ODP.Net and without Entity - it works fine.

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 is a view.

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

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

This may be wrong. But I do not know how to create objects that will have access to this view. The user has permission only for SELECT. I want to perform read-only operations.

+6
source share
1 answer

The implementation of Oracle's Entity Infrastructure Provider is very weak, but there are some ways to do this.

  • Simple but annoying is using NULL or your own database initialization:

     Database.SetInitializer<DatabaseContext>(null); 

or

 class DatabaseInitializer : IDatabaseInitializer<DatabaseContext> { public void InitializeDatabase(DatabaseContext context) { // your implementation } } Database.SetInitializer(new DatabaseInitializer()); 

Set initialization before the first access to your database.

  1. If you want to use migrations, create your own views, and then add the migration ignoring the changes, for example, using the add-migration initial -ignorechanges package console. This will force EF to ignore the inconsistencies between the schema and the database model (since it only checks tables from ALL_TABLES , not the views), so it will not try to create a table. There is an error in the Oracle EF implementation: if the initial migration is empty, it reduces and recreates the __MigrationHistory table, so either your initial migration must contain at least one table before adding view migration, or you need to add the table later.
+4
source

Source: https://habr.com/ru/post/983238/


All Articles