在SQL Server和SQL Compact中使用EF [英] Using EF in SQL Server and SQL Compact

查看:93
本文介绍了在SQL Server和SQL Compact中使用EF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在使用WPF桌面应用程序,它有两个关于数据存储的令人不快的选择。 SQL Server ou  SQL Compact Edition。两个数据库都具有相同的实体模型(.EDMX)。


在应用程序中,我们会检查(根据用户配置或甚至安装在PC上的许可证),如果 应用程序将连接到本地(压缩)或服务器(SQL 2008)数据库。


为了使其工作,我们必须执行一些技巧。我们使用 。 EDMX设计器配置为使用SQL compact,因此默认情况下,每个设置都可以使用它。现在添加对SQL服务器的支持:


1  -  我们更改了"元数据工件 处理"。 EDMX模型上的属性 到"复制到输出目录";


2 - 编译项目,获取SSDL和MSL生成的文件并将它们添加到项目中(将它们标记为嵌入式资源);


3 - 移回"元数据工件 处理" EDMX模型上的属性 到"嵌入输出程序集";


4 - 更改SSDL和MSL上的一些标记。我们发现在Visual Studio 2010上更改MSL是必要的。它不是在2008年。不知道为什么;


5 - 显然更新了SQL Server数据库模型(但这是这篇文章的范围);


正如您所看到的,每次我们对数据库模型进行一些更改时,这都是一个棘手且繁琐的过程。


我们可以做些什么来支持这两个数据存储并使这个过程更自动,更不容易出错?


请问,


Igor。


INOVATIVA Tecnologia项目经理www.inovativatec.com

解决方案

Hello Igor,


 


欢迎来到EF论坛!


 


我不认为VS有一些内置功能可以自动完成这个过程。  
在SQL Compact上使用Entity Framework可能会有一些限制,
< span style ="font-family:Calibri"> http://technet.microsoft.com/en-us/library/cc835494.aspx
 
  所以我们需要非常小心地修改.edmx的SSDL和MSL部分,这使得第4步有点烦意见。 
J   
我们可以创建一些工具来更自动化。  


 


SSDL中明显的不同之处在于我们没有SQL Compact数据库的schema属性。  
编辑SSDL和MSL时,我认为
LINQ to XML 可以帮助我们简化流程。  &NBSP;
  在VS中自动生成代码时,T4模板通常是个不错的选择,
http://msdn.microsoft.com/en-us/ library / bb126445.aspx   


 


希望你度过愉快的一天!


< span style ="font-size:12pt">  


 


最诚挚的问候,b
Lingzhi Sun


MSDN订阅者支持


如果您对我们的支持有任何反馈,请联系
msdnmg@microsoft.com


Hello all,

I'm working in a WPF desktop application that has two distintic options regarding the data storage. SQL Server ou SQL Compact Edition. Both databases have the same entity model (.EDMX).

At application lauch, we make a check (based on user configuration or even licenses installed on the PC) if the application will connect to the local (compact) or server (SQL 2008) databases.

In order to make it work, we had to perform some tricks. We use the .EDMX designer configured to work with the SQL compact, so by default, everyting is set to work with it. Now to add support for SQL server:

1 - We change the "Metadata Artifact Processing" property on the EDMX model to "Copy to output directory";

2 - Compile the project, get both SSDL and MSL generated files and add them to the project (mark them as an embedded resource);

3 - Move back the "Metadata Artifact Processing" property on the EDMX model to "Embed in Output Assembly";

4 - Change some tags on both SSDL and MSL. We discovered that changing MSL is necessary on Visual Studio 2010. It was not in 2008. Don't know why;

5 - Obviously update the SQL server database model (but this is out of the scope of this post);

As you can see this is a tricky and cumbersome procedure to be performed every time we make some change on the database model.

Is there any thing we could do to suppor both data stores and make this process more automatic and less error-prone?

Kindly Regards,

Igor.


Project Manager at INOVATIVA Tecnologia www.inovativatec.com

解决方案

Hello Igor,

 

Welcome to EF forum!

 

I don’t think VS has some built-in feature to make the process automatically.   Using Entity Framework on SQL Compact can have some limitations, http://technet.microsoft.com/en-us/library/cc835494.aspx.   So we need to be very careful to modify the SSDL and MSL section of the .edmx, which makes the step 4 a little annoying in my opinion.  J   We can create some tools to make it more automatically.  

 

The obvious different in the SSDL is that we don’t have the schema attribute for the SQL Compact database.   When editing the SSDL and MSL, I think LINQ to XML can help us to make the process easier.    When it comes to auto-generating codes in VS, T4 template is often a good option, http://msdn.microsoft.com/en-us/library/bb126445.aspx.  

 

Hope you have a nice day!

 

 

Best Regards,
Lingzhi Sun

MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


这篇关于在SQL Server和SQL Compact中使用EF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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