使用SQL Server Compact与实体框架的连接字符串? [英] Connection string for using SQL Server Compact with Entity Framework?

查看:104
本文介绍了使用SQL Server Compact与实体框架的连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试使用Google了。我已经安装了SQL Server CE 4.0,并且具有EF 4.1,但是我无法获得正确的连接字符串。 connectionstrings.com 中的任何内容都适用于我。

I'm done trying to Google for this. I have installed SQL Server CE 4.0, and have EF 4.1, but I can't get a proper connection string. Nothing on connectionstrings.com applies to me.

我只想创建一个 SqlCeEngine 对象,但无论我尝试什么都有一些例外。最近一直是

I just want to create a SqlCeEngine object, but no matter what I try I get some exception. Most recently it's been


连接字符串中的未知连接选项

Unknown connection option in connection string

与元数据,应用,提供者或提供者连接字符串之后。我知道EF要求连接字符串中的元数据。我不能想象没有提供商连接字符串有什么可以做的。

with either "metadata", "app", "provider", or "provider connection string" after it. I know EF requires metadata in the connection string. And I can't imagine how anything could do without "provider connection string".

到目前为止,我有这样的:

So far I have this:

<add name="DBContext" 
     connectionString="provider connection string=&quot;Data Source=MyDbFile.sdf;Persist Security Info=False;&quot;" 
     providerName="System.Data.EntityClient" />

有一点我有元数据:

<add name="DBContext" 
     connectionString="metadata=res://*/Data.DBContext.csdl|res://*/Data.DBContext.ssdl|res://*/Data.DBContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyDbFile.sdf;Persist Security Info=False;&quot;" 
     providerName="System.Data.EntityClient" />

是否需要元数据?连接字符串的app部分中有什么?提供者应该是什么, System.Data.SqlClient 或某些SQL Server CE版本? (当我尝试添加引用时,我仍然找不到,我的添加引用窗口仍然只包含 System.Data.SqlServerCe 版本3.5.1.0。)还是没有?

Does it need metadata or not? What goes in the "app" part of the connection string? What should the provider be, System.Data.SqlClient or some SQL Server CE version? (which I still can't find when I try to add references. My add references window still only contains System.Data.SqlServerCe version 3.5.1.0.) Or nothing?

providerName 属性中应该怎么办?正确的是 System.Data.EntityClient 就像这里有10个不同的变量,每个组合给我一个新的同样神秘的错误,没有一个在Google上有用的东西。我在我的智慧的尽头。这是甚至可能吗?

And what should go in the providerName attribute? Is System.Data.EntityClient correct? It's like there are 10 different variables here and every combination gives me a new equally mysterious error, none of which turns up anything useful on Google. I'm at my wits' end. Is this even possible?

推荐答案

您可以在App.config文件(EF5 Code first migrations and SQL Server CE 4.0 ):

You could try this in your App.config file (EF5 Code first migrations and SQL Server CE 4.0):

<connectionStrings>
    <add name="DefaultConnection"
         providerName="System.Data.SqlServerCe.4.0"
         connectionString="Data Source=|DataDirectory|\Data\ProjectDb.sdf"/>
</connectionStrings>

在你 ProjectDb class: p>

And in you ProjectDb class:

class ProjectDb : DbContext
{
    public ProjectDb()
        : base("DefaultConnection")
    {

    }
}

工作就像一个魅力。

您可以在这里找到更多信息: http://blogs.msdn.com/b/adonet/archive /2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-2-connections-and-models.aspx

You can find more information here: http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-2-connections-and-models.aspx

这篇关于使用SQL Server Compact与实体框架的连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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