简体   繁体   English

从SQL Server CE切换到SQL Server Express实体问题

[英]Switching from SQL Server CE to SQL Server Express entity issue

My application uses SQL Server Ce for the database and Entity Framework as the ORM. 我的应用程序将SQL Server Ce用于数据库,并将实体框架用作ORM。 Now I'm trying to switch to SQL Server Express but I'm having trouble doing so. 现在,我尝试切换到SQL Server Express,但是这样做很麻烦。

UPDATE 更新

So after banging my head for 3 hours I finally figured out that you cannot use an Entity model generated from a SQL Server CE database against a SQL Server (in my case Express version). 因此,在敲了三个小时之后,我终于发现您不能对SQL Server(在我的情况下是Express版本)使用从SQL Server CE数据库生成的实体模型。

I used a Diff program to view the generated files (Designer.cs) for both databases and I noticed these differences in the file: 我使用了一个Diff程序来查看两个数据库的生成文件(Designer.cs),我注意到文件中的这些区别:

SQL Server CE                          SQL Server 
FK__Download__000000000000003F         FK__Download__PlaneI__0519C6AF 

So I have to create two entity models, but how can I interchange between the two in my program? 因此,我必须创建两个实体模型,但是如何在程序中在两者之间互换?

If I create two entity models, I'll have two classes with the same object names. 如果创建两个实体模型,则将有两个具有相同对象名称的类。

Thanks in advance 提前致谢

The EDMX file actually consists out of three parts. EDMX文件实际上由三部分组成。

  • CSDL, your conceptual model CSDL,您的概念模型
  • SSDL, the storage model SSDL,存储模型
  • MSL, the mapping between those two. MSL,两者之间的映射。

Normally these three parts are embedded in as a resource in your assembly and the connection string that you use tells the runtime to look for them in that assembly. 通常,这三个部分作为资源嵌入到程序集中,并且您使用的连接字符串告诉运行时在该程序集中查找它们。

You can however use physical files and deploy them with your application. 但是,您可以使用物理文件并将其与应用程序一起部署。 In such a way you can use the same CSDL but a different set of SSDL/MSL for the specific database. 这样,您可以为特定数据库使用相同的CSDL,但使用不同的SSDL / MSL集。 In that way you can reuse your entity model against both your SqlCE database and a SQL Server database. 这样,您可以针对SqlCE数据库和SQL Server数据库重用实体模型。

Here you can find a blog post about swapping EF metadata 在这里您可以找到有关交换EF元数据的博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM