entity-framework-4 – 使用SQL Server Compact与实体框架的连接
我已经尝试了谷歌这样做.我已经安装了SQL Server CE 4.0,并且具有EF 4.1,但是我无法获得正确的连接字符串. connectionstrings.com上没有任何内容适用于我.
我只是想创建一个SqlCeEngine对象,但无论我尝试什么都有一些例外.最近一直是
“元数据”,“应用程序”,“提供者”或“提供者连接字符串”之后.我知道EF要求连接字符串中的元数据.而且我无法想象没有“提供者连接字符串”可以做什么. 到目前为止我有这个: <add name="DBContext" connectionString="provider connection string="Data Source=MyDbFile.sdf;Persist Security Info=False;"" 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="Data Source=MyDbFile.sdf;Persist Security Info=False;"" providerName="System.Data.EntityClient" /> 是否需要元数据?连接字符串的“app”部分中有什么?提供者应该是什么,System.Data.SqlClient或一些SQL Server CE版本? (当我尝试添加引用时,我仍然找不到,我的添加引用窗口仍然只包含System.Data.SqlServerCe版本3.5.1.0.)还是没有? 在providerName属性中应该怎么做? System.Data.EntityClient是否正确?就像这里有10个不同的变量,每个组合给我一个新的同样神秘的错误,没有一个在Google上有用的东西.我在我的智慧的尽头.这是甚么可能吗? 解决方法您可以在App.config文件(EF5代码第一次迁移和SQL Server CE 4.0)中尝试这样做:<connectionStrings> <add name="DefaultConnection" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|DataProjectDb.sdf"/> </connectionStrings> 在你的ProjectDb类中: 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |