Oracle数据库用EF操作的示例
Using EF Oracle Sample Provider with EDM Designer (from msdn)
Many people are asking if it is possible to use EFOracleProvider with EDM Designer in Visual Studio 2008 SP1. The answer is yes, but because the sample doesn't include a DDEX provider required for VS integration, there are certain steps that have to be run manually.
I've compiled a step-by-step guide for those interested in trying this out (this assumes NorthwindEF sample database installed according to instructions included with the sample, but it should be straightforward to adjust it to your own setup)
PART 1 : INSTALLING ORACLE SAMPLE PROVIDER
1. Download and unzip EFOracleSampleProvider.zip from http://code.msdn.com/EFOracleProvider
2. Follow instructions in the README.txt to set up a sample database.
3. Open elevated Visual Studio instance. Build the sample project.
4. Open elevated command prompt and open machine.config using notepad:
notepad %WINDIR%\Microsoft.NET\Framework\v2.0.50727\config\machine.config
5. Find <DbProviderFactories> section and add EFOracleProvider entry:
<add name="EF Oracle Data Provider" invariant="EFOracleProvider"
description="EF Provider for Oracle testing"
type="EFOracleProvider.EFOracleProviderFactory, EFOracleProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b"/>
6. The completed system.data section has to look similar to this:
<system.data>
<DbProviderFactories>
<add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="EF Oracle Data Provider" invariant="EFOracleProvider" description="EF Provider for Oracle testing" type="EFOracleProvider.EFOracleProviderFactory, EFOracleProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b"/>
<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
PART 2: GENERATING MODEL FROM ORACLE DATABASE
7. Create a new project in VS. For simplicity let's create a console application
8. Open elevated command prompt. Enter the directory that contains the newly created project and run the following command:
%WINDIR%\Microsoft.NET\Framework\v3.5\edmgen.exe /provider:EFOracleProvider /mode:fullgeneration /connectionstring:"data source=XE;user id=edmuser;password=123456" /project:NorthwindEFModel
The output should be:
Microsoft (R) EdmGen version 3.5.0.0
Copyright (C) 2008 Microsoft Corporation. All rights reserved. Loading database information...
warning 6005: The data type 'timestamp(9)' is not supported, the column 'OrderDate' in table 'dbo.Orders' was excluded.
warning 6005: The data type 'timestamp(3)' is not supported, the column 'RequiredDate' in table 'dbo.Orders' was excluded.
Writing ssdl file...
Creating conceptual layer from storage layer...
Writing msl file...
Writing csdl file...
Writing object layer file...
Writing views file... Generation Complete -- 0 errors, 2 warnings
9. This will create a bunch of NorthwindEFModel.* files for you.
10. Open Northwind.ssdl file in a text editor and replace all instances of Schema="dbo" with empty string (this is needed because tables in the sample Oracle database don't use a schema)
11. In order to use generated model in the EF Ddesigner, we have to create NorthwindEFModel.edmx file. This can be done manually (just copy/paste contents of individual files into an empty EDMX as indicated by the comments) or by using EdmGen2 tool from Code Gallery:
C:\Path\To\EdmGen2.exe /toedmx NorthwindEFModel.csdl NorthwindEFModel.ssdl NorthwindEFModel.msl
12. This will create NorthwindEFModel.edmx, which we can add to the project in VS.
13. At this point you can now delete the following files generated by EdmGen.exe, which won't be necessary:
- NorthwindEFModel.csdl
- NorthwindEFModel.ssdl
- NorthwindEFModel.msl
- NorthwindEFModel.ObjectLayer.cs
- NorthwindEFModel.Views.cs
PART 3: TESTING GENERATED MODEL
14. The only remaining thing to do is to add App.config file with connection string for our Oracle database:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="NorthwindEFModelContext"
connectionString="provider=EFOracleProvider;
metadata=res://*/NorthwindEFModel.csdl|res://*/NorthwindEFModel.ssdl|res://*/NorthwindEFModel.msl;
Provider Connection String='data source=XE;user id=edmuser;password=123456'"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
15. We can now try out our model by running a sample LINQ to Entities query:
using (NorthwindEFModelContext context = new NorthwindEFModelContext())
{
foreach (var c in context.Customers.Where(c=>c.City == "Seattle"))
{
Console.WriteLine(c.CompanyName);
}
}
本人用我的poor英文水平,简单的翻译了一下(供参考):
许多人问它是否可能与 EDM 设计器在 Visual Studio 2008 SP1 中使用EFOracleProvider 。答案是肯定的但因为该示例不包括 VS 集成所需的 DDEX 提供程序,有某些必须手动运行的步骤。
我总结了一个分步指南,对于那些有兴趣尝试这 (这是假设 NorthwindEF 示例数据库根据示例,附带的说明,安装,但它应该很简单,调整到您自己的安装程序)
第 1 部分: 安装 ORACLE 示例提供程序
1.下载并解压缩 EFOracleSampleProvider.zip 从http://code.msdn.com/EFOracleProvider
2.按照说明在 README.txt 中的设置一个示例数据库。
3.开放提升的 Visual Studio 实例。生成示例项目。
4.打开提升的命令提示符并 machine.config 使用记事本打开:
notepad %WINDIR%\Microsoft.NET\Framework\v2.0.50727\config\machine.config
5.找到 <DbProviderFactories> 部分并添加 EFOracleProvider 条目:
<add name="EF Oracle Data Provider" invariant="EFOracleProvider"
description="EF Provider for Oracle testing"
type="EFOracleProvider.EFOracleProviderFactory, EFOracleProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b"/>
6.已完成的 system.data 部分有看上去类似这样:
<system.data>
<DbProviderFactories>
<add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="EF Oracle Data Provider" invariant="EFOracleProvider" description="EF Provider for Oracle testing" type="EFOracleProvider.EFOracleProviderFactory, EFOracleProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def642f226e0e59b"/>
<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
第 2 部分: 从 ORACLE 数据库生成模型
7.在 VS 中创建一个新的项目。为简单起见,让我们创建一个控制台应用程序
8.打开提升的命令提示符。输入包含新创建的项目的目录,然后运行以下命令:
%WINDIR%\Microsoft.NET\Framework\v3.5\edmgen.exe /provider:EFOracleProvider /mode:fullgeneration /connectionstring:"data source=XE;user id=edmuser;password=123456" /project:NorthwindEFModel
输出应该是:
Microsoft (R) EdmGen version 3.5.0.0
Copyright (C) 2008 Microsoft Corporation. All rights reserved. Loading database information...
warning 6005: The data type 'timestamp(9)' is not supported, the column 'OrderDate' in table 'dbo.Orders' was excluded.
warning 6005: The data type 'timestamp(3)' is not supported, the column 'RequiredDate' in table 'dbo.Orders' was excluded.
Writing ssdl file...
Creating conceptual layer from storage layer...
Writing msl file...
Writing csdl file...
Writing object layer file...
Writing views file... Generation Complete -- 0 errors, 2 warnings
9.这将为您创建 NorthwindEFModel.* 文件一的束。
10.在文本编辑器中打开 Northwind.ssdl 文件并替换所有实例的架构 ="dbo"与空字符串 (这需要,因为示例 Oracle 数据库中的表不使用架构)
11.对在 EF Ddesigner 中使用生成的模型,我们必须创建 NorthwindEFModel.edmx 文件。这可以手动完成 (只复制/粘贴内容成空 EDMX 如评论所示的单个文件) 或使用EdmGen2 工具从代码库:
C:\Path\To\EdmGen2.exe /toedmx NorthwindEFModel.csdl NorthwindEFModel.ssdl NorthwindEFModel.msl
12.这将创建 NorthwindEFModel.edmx,我们可以添加到项目中,VS。
13.在这一点,你现在可以删除生成 EdmGen.exe,这不会是必需的以下文件:
- NorthwindEFModel.csdl
- NorthwindEFModel.ssdl
- NorthwindEFModel.msl
- NorthwindEFModel.ObjectLayer.cs
- NorthwindEFModel.Views.cs
第 3 部分: 测试生成的模型
14.剩下的唯一要做是我们的 Oracle 数据库与连接字符串 App.config 文件中添加:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="NorthwindEFModelContext"
connectionString="provider=EFOracleProvider;
metadata=res://*/NorthwindEFModel.csdl|res://*/NorthwindEFModel.ssdl|res://*/NorthwindEFModel.msl;
Provider Connection String='data source=XE;user id=edmuser;password=123456'"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
15.我们现在可以尝试我们的模型通过对实体查询运行 LINQ 示例:
using (NorthwindEFModelContext context = new NorthwindEFModelContext())
{
foreach (var c in context.Customers.Where(c=>c.City == "Seattle"))
{
Console.WriteLine(c.CompanyName);
}
}
Oracle数据库用EF操作的示例的更多相关文章
- Oracle数据库安装图文操作步骤1
Oracle数据库安装图文操作步骤 一.Oracle 下载 注意Oracle分成两个文件,下载完后,将两个文件解压到同一目录下即可. 路径名称中,最好不要出现中文,也不要出现空格等不规则字符. 官 ...
- oracle 数据库——知识点总结(加示例)
新入oracle数据库,把目前学到的知识点记录下来,可能都比较基础,但还是比较全的,里面的示例都是自己在PL/SQL中跑过的,如果有错误,还望各位大侠指出哈. 创建用户 1.创建用户(使用管理员身份创 ...
- 混合框架中Oracle数据库的还原处理操作
在较早期的随笔<Oracle如何实现创建数据库.备份数据库及数据导出导入的一条龙操作>粗略介绍了Oracle数据库的备份还原操作,本文想从开发框架的基础上介绍Oracle数据库的脚本或者还 ...
- oracle数据库的简单操作
本操作是在oracle的11g版本中的操作 一.数据库登录操作: 如果是在服务器上登录oracle,需要先切换到oracle用户再进行登录 #切换到oracle用户 su - oracle #登录or ...
- 使用spring框架的JdbcTemplate实现对Oracle数据库的简单操作实例
最近实现了一个小功能,针对Oracle数据库两张关联表进行查询和修改,因为比较简单,所以选择了spring框架里的JdbcTemplate.JdbcTemplate算是老古董了,是当年spring为了 ...
- Oracle数据库安装图文操作步骤
一.Oracle 下载 注意Oracle分成两个文件,下载完后,将两个文件解压到同一目录下即可. 路径名称中,最好不要出现中文,也不要出现空格等不规则字符. 官方下地址: http://www.o ...
- oracle数据库升级dbua操作阻塞解决方法(解决ORA-32004报错)
操作环境 1.SuSE11sp3操作系统 2.oracle 11.2.0.3版本升级到11.2.0.4版本 问题现象 oracle 11.2.0.3版本升级到11.2.0.4版本时执行dbua命令 ...
- oracle数据库列的操作
本章和大家分享一下如何在数据库中进行列的一些相关操作. 1.增加列名 (我们先来看一个原始版本) 下面我们增加一个列名tel 记住,增加列时需要把列对应的数据类型要说明,不然会报错. alter t ...
- Oracle数据库SQL语句操作大全汇总
数据库各个表空间增长情况的检查: SQL >SELECT A.TABLESPACE_NAME,( 1-(A.TOTAL)/B.TOTAL)* 100 USED_PERCENT FROM (SEL ...
随机推荐
- 十三、实现Comparable接口和new Comparator<T>(){ }排序的实现过程
参考:https://www.cnblogs.com/igoodful/p/9517784.html Collections有两种比较规则方式,第一种是使用自身的比较规则: 该类必须实现Compara ...
- python+selenium,打开浏览器时报selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
有一年多没写web自动化了,今天搭建环境的时候报了一个常见错误,但是处理过程有点闹心,报错就是常见的找不到驱动<selenium.common.exceptions.WebDriverExcep ...
- windows service 2008 R2 升级 sp1遇到的问题
因为我的程序是以vs2015开发的,所以在在布署windows service 2008 R2 项目的时候报出 红框里的错,说明要安装.net framework4.6. 感觉so easy,下载一个 ...
- python 字符串 转 bit, bitarray 异或加密
Python中异或加密要将str 转为 bitarray, 提示: int类型和纯数字的字符串也可以异或处理, 可能更方便 from bitarray import bitarray def str2 ...
- Windows PowerShell基本语法及常用命令
PowerShell常用命令: 一 Get类 1.Get-Command : 得到所有PowerShell命令,获取有关 cmdlet 以及有关 Windows PowerShell 命令的其他元素的 ...
- js最实用string(字符串)类型的使用及截取与拼接详解
var a = '世界上最远的距离不是天涯海角'; 一.通过字符获取位置或通过位置获取字符: //指定位置返回字符console.log(str.charAt(1));console.log(str[ ...
- Winform 利用 Oracle.ManagedDataAccess访问Oracle数据库
Winform 利用 Oracle.ManagedDataAccess访问Oracle数据库时出现以下错误: Message = "每个配置文件中只允许存在一个 <configSect ...
- STS中db.properties配置文件
db.name=root db.password=root db.url=jdbc:mysql://localhost:3306/day13?useUnicode=true&character ...
- this()基础用法
this()表示调用构造方法,此种调用只能用在构造方法中,即构造方法中调用构造方法this(实参). 1.this().this(实参)必须方法构造方法的第一行 2.在有参数构造方法中调用无参数构造方 ...
- SHELL脚本学习-定时检查Oracle alert日志并发送mail
对于DBA来说,检查alert日志是日常工作.告警日志日积月累往往很大,而且每次在服务器上查看或者下载到目标主机查看都十分不方便. 为了方便,以下做出两种情况:(其他情况类推) 第一场景:每天早上上班 ...