如何使用实体框架实现数据库独立性 [英] How to Implement Database Independence with Entity Framework

查看:150
本文介绍了如何使用实体框架实现数据库独立性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用实体框架来启动一个相当简单的示例项目。在项目中,我已经从SQL Server 2000数据库创建了一个新的实体数据模型。我可以使用LINQ to Entities查询数据并在屏幕上显示值。

I have used the Entity Framework to start a fairly simple sample project. In the project, I have created a new Entity Data Model from a SQL Server 2000 database. I am able to query the data using LINQ to Entities and display values on the screen.

我有一个非常相似的模式的Oracle数据库(我试图确切地说但我不知道Oracle的所有细节)。我希望我的项目能够以最小的努力在SQL Server和Oracle数据存储上运行。我希望我可以简单地更改我的实体数据模型的配置字符串,实体框架将会处理其余的。但是,似乎无法像以前那样无缝工作。

I have an Oracle database with an extremely similar schema (I am trying to be exact but I do not know all the details of Oracle). I would like my project to be able to run on both the SQL Server and Oracle data stores with minimal effort. I was hoping that I could simply change the configuration string of my Entity Data Model and the Entity Framework would take care of the rest. However, it appears that will not work at seamlessly as I thought.

有没有人做过我想做的事情?再次,我试图编写一个应用程序,可以使用实体框架以最小的努力来从SQL Server或Oracle数据库查询(和更新)数据。次要目标是在数据存储之间来回切换时不必重新编译应用程序。如果我必须从数据库更新模型可能是确定,因为我不需要重新编译,但我宁可不必去这条路线。有没有人知道可能需要的任何步骤?

Has anyone done what I am trying to do? Again, I am trying to write an application that can query (and update) data from a SQL Server or Oracle database with minimal effort using the Entity Framework. The secondary goal is to not have to re-compile the application when switching back and forth between data stores. If I have to "Update Model from Database" that might be ok because I wouldn't have to recompile, but I'd prefer not to have to go this route. Does anyone know of any steps that might be necessary?

推荐答案

持久性无知这个术语一般都被理解为你的实体类没有被框架依赖性淹没(对于N层场景很重要)。现在不是这样,因为实体类必须实现某些EF接口(IPOCO),而不是纯旧的CLR对象。正如另一个海报所提到的,有一个解决方案称为持久性无知(POCO)适用于实体框架的V1 V1,而EF V2将支持POCO开箱即用。

What is generally understood under the term "Persistence Ignorance" is that your entity classes are not being flooded with framework dependencies (important for N-tier scenarios). This is not the case right now, as entity classes must implement certain EF interfaces ("IPOCO"), as opposed to plain old CLR objects. As another poster has mentioned, there is a solution called Persistence Ignorance (POCO) Adapter for Entity Framework V1 for that, and EF V2 will support POCO out of the box.

但我认为你真正想到的是数据库独立性。使用一个大的配置XML,包括存储模型,概念模型和在设计时将生成类型的ObjectContext的两个映射之间的映射,我也很难形象地如何透明地支持两个数据库。

But I think what you really had in mind was database independence. With one big configuration XML that includes storage model, conceptual model and the mapping between those two from which a typed ObjectContext will be generated at designtime, I also find it hard to image how to transparently support two databases.

可能看起来更有希望的是应用与数据库无关的ADO.NET提供程序,例如 DataDirect 。 DataDirect也宣布了EF支持Q3 / 2008。

What probably looks more promising is applying a database-independent ADO.NET provider like the one from DataDirect. DataDirect has also announced EF support for Q3/2008.

这篇关于如何使用实体框架实现数据库独立性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆