实体框架 Oracle 和 Sql Server - 如何构建独立于数据库的应用程序
我们正在尝试构建一个数据访问层以同时使用 Oracle 和 SQL Server(不是同时).
We are trying to build a data access layer for using both Oracle and SQL Server (not at the same time).
我们使用 EF 模型优先来创建模型并创建 SQL 脚本来构建数据库.我们的第一个想法是创建 2 个 EDMX 文件,每种类型一个,并根据客户的需要使用适当的文件.我们正在使用 Oracle 和 SQL Server 数据库生成工作流和 DDL 生成模板来为每个数据库创建脚本.
We use EF Model-first for creating the model and the create the SQL scripts for building the database. Our first thought was to create 2 EDMX files, one for each type, and use the appropriate one depending on the client's need. We are using the Oracle and SQL Server database generation workflow and DDL generation template to create the scripts for each database.
我们的主要问题是当数据库架构发生变化时,我们不想删除并重新创建数据库,而只想创建迁移脚本以根据我们的模型更新数据库(客户端有很多数据会丢失).
Our main problem is when the database schema changes we do not want to drop and recreate the DB but only create the migration scripts to update the DB base on our model (clients have many data that will be lost).
我们使用 EF 电源包来提取 SQL Server 的迁移脚本,但对于 Oracle,没有类似的东西.
We use EF power pack for extracting the migration scripts for SQL Server but there is nothing like it for Oracle.
我们希望帮助我们找到一个好的数据层(如果可能且不复杂,则为 Oracle 和 SQL Server 提供 1 个 EDMX)以及从我们的模型生成数据库更改以在新应用程序的情况下更新现有客户端数据库的好方法发布
We want help to find a good data layer (1 EDMX for both Oracle and SQL Server if it's possible and not complicated) and a good way to generate database changes from our model to update existing client DBs in case of a new application release
我们发现这是一个起点http://msdn.microsoft.com/en-us/data/ff830362 但没有提及获取 Oracle 支持.
We found this as a starting point http://msdn.microsoft.com/en-us/data/ff830362 but there is not mention for Oracle support.
我们已经尝试过代码优先和 EF 迁移,但 Oracle 在数据库创建和迁移方面再次失败了.
We have tried code-first and EF Migrations but Oracle failed us again on the DB creation and migration.
关于我们如何实现这一点的任何建议?
Any recommendation on how we can accomplish this?
谢谢
推荐答案
没有办法为 SQL Server 和 Oracle 提供单一的 EDMX.EDMX 由 CSDL(实体定义)、SSDL(数据库定义)、MSL(这些定义之间的映射)三部分组成.SSDL 必须始终以具体数据库为目标,因此您至少需要为 Oracle 和 SQL Server 提供单独的 SSDL,如果幸运的话,您也不需要单独的 MSL(映射必须完全相同,如果您使用任何工具生成,这可能不会发生数据库).
There is no way to have single EDMX for both SQL Server and Oracle. EDMX consists of three parts CSDL (entity definition), SSDL (database definition), MSL (mapping between those definitions). SSDL must always target concrete database so you need at least separate SSDL for Oracle and SQL Server and if you are lucky you will not need separate MSL as well (mapping must be exactly same which will probably not happen if you are using any tool to generate the database).
因此,您始终需要至少部分 EDMX 文件用于第二个数据库并手动维护它.
So you always need at least part of EDMX file for second DB and manually maintain it.
如果您需要支持 Oracle 的数据库迁移,您必须从 Oracle(或第三方)寻找工具.例如 RedGate 为 SQL Server 和 Oracle.
If you need DB migration supporting Oracle you must look for tool from Oracle (or third party). For example RedGate offers tools supporting schema migration for both SQL Server and Oracle.
Visual Studion 高级版和旗舰版还提供了用于比较数据库架构的工具.它默认只支持 SQL Server 但 Toad Extensions 也应该添加对 Oracle 的支持.
Visual Studion Premium and Ultimate edition also offers tools for comparing database schemas. It by default supports only SQL Server but Toad Extensions should add support for Oracle as well.
一旦您拥有这些工具中的任何一个,您只需将部署在客户服务器上的架构与您的新架构进行比较,该工具就会为您创建迁移脚本.
Once you have any of these tools you just need to compare schema deployed on customer server with your new schema and the tool should create migration script for you.
相关文章