实体框架会起作用吗? [英] Will Entity Framework work?

查看:59
本文介绍了实体框架会起作用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在开始一个新项目,并希望得到一些EF专家的一些意见,以确定它是否适合这个项目。基本上我想开发一个位于任何数据库(Oracle,SQL等)之上的软件。系统
将允许用户通过从允许的预定义数据集中选择来查询他们自己的数据。

Hi all, I am starting on a new project and would like to get some input from some of you EF experts as to it's suitability on this project. Basically i want to develop a piece of software that will sit on top of any database (Oracle, SQL etc). The system will allow users to interrogate their own data by selecting from allowable predefined datasets.

一方面,实体与数据交互的自然c#linq实际上是真的适合这样的系统。我担心使用EF我将无法将其插入任何数据库。请记住,与DB的链接将是一个运行时的事情,我不会提前知道数据库。

On one hand the natural c# linq to entities way of interacting with the data would really suit such a system. I am worried that with EF I won't be able to plug it into any database. Remember that the linking with the DB will be a run time thing, I won't know the DB in advance.

我有一些想法是编写一个接口并允许DLL将被插入每个客户数据库,DLL将被动态加载并包含所有数据库信息(实体模型等)。

Some thoughts I had was to write an interface and allow DLL's to be plugged in for each customers DB, the DLL would be dynamically loaded and would contain all the DB information (the entity model etc.).

EF是否真的适合这种类型的事情是你提前不知道数据库?其中很大一部分是能够在运行时读取客户DB的元数据。

Is EF really suited to this sort of thing were you don't know the DB in advance? A big part of this is to be able to read the customer DB's meta data at runtime.

我真的很感激你的想法吗?

I'd really appreciate you thoughts?

谢谢  ;

推荐答案

是的,您应该能够在运行时更改连接字符串。你可以这样做:

Yes, you should be able to change the connection string at runtime. You can do it like this:

 

var builder = new EntityConnectionStringBuilder ();
builder . Metadata = "res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl" ;
builder . Provider = "System.Data.SqlClient" ;
builder . ProviderConnectionString = "[YOUR DB CONNECTION STRING]";

EntityConnection conn = new EntityConnection(builder.ToString());

 

你刚才需要知道您将支持的提供程序,在本例中为MS SQL Server的SqlClient。然后设置
的Connection属性
ObjectContext

You just need to know the provider that you will support, in this case SqlClient for MS SQL Server. Then you set the Connection property of your ObjectContext .


这篇关于实体框架会起作用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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