实体框架与OleDB连接 - 我只是简单的坚果? [英] Entity Framework with OleDB connection - am I just plain nuts?

查看:96
本文介绍了实体框架与OleDB连接 - 我只是简单的坚果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实体框架,我想连接到Access 2007数据库。

I'm experimenting with the Entity Framework and I want to connect to an Access 2007 database.

以下代码的灵感来自于 http://msdn.microsoft.com/en-us/library/system。 data.entityclient.entityconnection.connectionstring.aspx

The following code is inspired by http://msdn.microsoft.com/en-us/library/system.data.entityclient.entityconnection.connectionstring.aspx

我怀疑我的错误结束了...

I suspect that I've got the wrong end of the stick...

OleDbConnectionStringBuilder oledbConn = new OleDbConnectionStringBuilder();

oledbConn.DataSource = @"..\..\..\..\Pruebas.accdb"; //yep Access 2007!

EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder ();
entityBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";
entityBuilder.ConnectionString = oledbConn.ToString();
EntityConnection ec = new EntityConnection(entityBuilder.ToString());
ec.Open();
ec.Close();

EntityConnectionStringBuilder告诉我它不支持DataSource属性。我可以与ADO.net连接良好,所以我知道路径和提供者是正确的。

The EntityConnectionStringBuilder tells me that it doesn't support the DataSource property. I can connect fine with ADO.net so I know that the path and the provider are correct.

这只是完全错误的方法吗?

Is this just the complete wrong approach?

推荐答案

您用于构建EF连接字符串的方法是正确的。

The approach you are using to build the EF connection string is correct.

实体框架仅适用于支持称为提供商服务的提供者(即SqlClient)。

The Entity Framework only works with Providers (i.e. SqlClient) that support something called provider services.

OleDB提供商不支持'提供商服务',因此您不能使用EF与OleDb(除非您可以找到支持EF的第三方OleDb提供商)。

The OleDB provider doesn't support 'Provider Services' so you can't use EF with the OleDb (unless you can find a third party OleDb provider with support for EF).

希望这有助于

Alex

(实体框架小组,Microsoft)

(Entity Framework Team, Microsoft)

这篇关于实体框架与OleDB连接 - 我只是简单的坚果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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