V
V
V Sh.2015-09-02 09:23:10
C++ / C#
V Sh., 2015-09-02 09:23:10

How to attach Entity Framework to Oracle DB?

Good day, Toaster!
I recently started studying Entity Framework (as part of studying MVC) and ran into a problem: I can’t pull data from a table. When trying to run an application that displays a list of books, the system writes: "Oracle.DataAccess.Client.OracleException: ORA-00942: user table or view does not exist."

And I do the following: I create a Book class in the Models folder of my MVC application.

namespace MVC4Test.Models
{
    public class Book
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Author { get; set; }
        public decimal Price { get; set; }
    }
}


Then I create a context using ENTITY FRAMEWORK.
using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Entity;

namespace MVC4Test.Models
{
    public class BookContext : DbContext
    {
        public DbSet<Book> BOOKS { get; set; }
        //public DbSet<Purchase> Purchases { get; set; }
    }
}


Then I try to get the list of books in the controller and pass it to the view:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC4Test.Models;

namespace MVC4Test.Controllers
{
    public class HomeController : Controller
    {
        BookContext db = new BookContext();

        public ActionResult Index()
        {
            IEnumerable<Book> books = db.BOOKS;
            ViewBag.Books = books;
            return View();
        }

    }
}


But I can't do anything. Running through the steps, I noticed that the query that is sent to the database is compiled as for MS SQL SERVER:
SELECT 
 CAST( "Extent1"."Id" AS number(10,0)) AS "C1", 
"Extent1"."Name" AS "Name", 
"Extent1"."Author" AS "Author", 
"Extent1"."Price" AS "Price"
FROM "dbo"."Books" "Extent1"


Naturally, if I run it in ORACLE, I get the above error. How can I deal with this and are there articles in Russian on the entity framework for working with the ORACLE database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kovalsky, 2015-09-02
@dmitryKovalskiy

1) Manual directly on the Oracle.com website.
2) How do you create connectionString? There must be heresy

res://*/Some.csdl|res://*/Some.ssdl|res://*/Some.msl;provider=System.Data.SqlClient;provider connection string="data source=MySQLServer;initial catalog=SomeDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"

And in this code there are 2 important points for Oracle. 1) it would be nice to replace the standard .NET provider with an oracle one (there are assemblies on the website). 2) Convert the connection string to the format
Another related link.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question