简体   繁体   中英

In Entity Framework, how to generate entities from different Oracle schemas in VS2017

I am currently attempting to generate code from tables from an existing Oracle 12 database from within Entity Framework 6. The problem I am having is that while it is able to see the schema that I own when I log into the environment, Entity Framework can't seem to see any other schemas that I have access to.

How can I change it so that I can see another schema?

I have used Entity Framework model-first and code-first. I can go in an manually change the schema on a generated table that I own in Oracle and it will work, but that would mean generating my own versions of tables from the other schema in my own schema just to be able to use them via Entity Framework.

Generating all the code from all the existing tables would be a cumbersome job otherwise.

How do I solve this problem?

Ok, I have solved the problem. There is a particular way to get schemas working with Oracle in Entity Framework, and you can get full use of Entity Framework, including the Designer/Canvas if you want.

First, in your application, using Nuget, install the Oracle.ManagedDataAccess.EntityFramework package. If you look at the Description of this package in Nuget, it says it depends on EntityFramework and Oracle.ManagedDataAccess. So install the one package and it will install all that, if its missing.

Next, if you read the comment at the bottom of that description, it says "Note: The 32-bit Oracle Developer Tools for Visual Studio download from http://otn.oracle.com/dotnet is required for Entity Framework design-time features and for other Visual Studio designers such as the TableAdapter Wizard. This NuGet download does not enable design-time tools, only run-time support."

So you need to install the Oracle Tools for Visual Studio that matches your environment. Installing ODTwithODAC packages won't give you the right outcome.

Finally, add a connection to the Oracle database. Then, open the Server explorer and find that connection. Right-click on the connection, and select Filters. Then select Displayed Schemas. Edit the value, adding in all the schemas you want to display, by clicking on the "..." button and selecting the schemas. Then click Update. Then click Ok.

Next time you want to select an object from a schema that you just added, it will appear in the Entity Framework list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM