简体   繁体   English

在Entity Framework中,如何从VS2017中的不同Oracle模式生成实体

[英]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. 我目前正在尝试从实体框架6中的现有Oracle 12数据库的表中生成代码。我遇到的问题是,当我登录环境时,它能够看到我拥有的架构,而实体框架可以似乎看不到我可以访问的任何其他架构。

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. 我可以手动更改在Oracle中拥有的已生成表上的模式,它将起作用,但这意味着从自己模式中的其他模式中生成表的自己版本,以便能够通过实体使用它们框架。

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. 有一种特殊的方法可以使模式在Entity Framework中与Oracle一起使用,并且可以充分利用Entity Framework,包括所需的Designer / Canvas。

First, in your application, using Nuget, install the Oracle.ManagedDataAccess.EntityFramework package. 首先,在您的应用程序中,使用Nuget,安装Oracle.ManagedDataAccess.EntityFramework软件包。 If you look at the Description of this package in Nuget, it says it depends on EntityFramework and Oracle.ManagedDataAccess. 如果您在Nuget中查看此程序包的说明,它说它取决于EntityFramework和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." 接下来,如果您阅读了该说明底部的注释,则该注释将显示为“注意:在实体框架设计时,需要从http://otn.oracle.com/dotnet下载32位的Oracle Developer Studio for Visual Studio。功能和其他Visual Studio设计器(例如TableAdapter向导)。此NuGet下载不启用设计时工具,仅启用运行时支持。”

So you need to install the Oracle Tools for Visual Studio that matches your environment. 因此,您需要安装与您的环境匹配的Oracle Tools for Visual Studio。 Installing ODTwithODAC packages won't give you the right outcome. 安装ODTwithODAC软件包不会给您正确的结果。

Finally, add a connection to the Oracle database. 最后,添加到Oracle数据库的连接。 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. 下次您要从刚刚添加的架构中选择一个对象时,该对象将出现在“实体框架”列表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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