EF4、自我跟踪、存储库模式、SQL Server 2008 和 SQL Server Compact

发布于 2024-08-30 10:38:52 字数 289 浏览 8 评论 0原文

我正在使用 Entity Frameworks 4 和自我跟踪实体创建一个项目。我希望能够从 sql server 2008 数据库或 sql server Compact 数据库获取数据(开关位于配置文件中)。我正在使用存储库模式,并且我将把自我跟踪实体放在单独的程序集中。

我需要两个 edmx 文件吗?如果是这样,如何在单独的程序集中生成一组 STE?我还需要生成两个上下文类吗?我不确定这一切的管道。有人可以帮忙吗?

达伦(Darren)

,我忘记补充一点,这两个数据库将是相同的,并且紧凑版本供离线使用。

I am creating a project using Entity Frameworks 4 and self tracking entities. I want to be able to either get the data from a sql server 2008 database or from sql server compact database (with the switch being in the config file). I am using the repository pattern and I will have the self tracking entities sitting in a separate assembly.

Do I need two edmx files? If so, how do I generate only one set of STE's in the separate assembly? Also do I need to generate two context classes as well? I am unsure of the plumbing for all this. Can anyone help?

Darren

I forgot to add that the two databases will be identical and that the compact version is for offline usage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕头说它不想醒 2024-09-06 10:38:52

只是为了跟进此事。最后我不得不维护两个单独的 edmx 文件,一个用于 sql server,一个用于紧凑。主要原因是紧凑型 3.5 不支持自动身份(如上面 Zeeshan 提到的)。这又导致了两个上下文类。在 sql server Compact 的上下文类中,我必须输入代码来检查插入、查询数据库以获取最新的 id 并在保存之前手动递增它。

值得庆幸的是,随着 Compact 4.0 的发布,这一点不再适用,因为它支持自动 id,并且您确实可以只使用一个 edmx 文件。

达伦

Just to follow up on this. In the end I had to maintain two separate edmx files, one for sql server and one for compact. The main reason being that compact 3.5 does not support auto identities (as mentioned above by Zeeshan). This in turn led to two context classes. In the context class for sql server compact I had to put code to check for insertions, query the database for the latest id and increment it manually before saving.

Thankfully with the release of compact 4.0 this no longer applies as it supports auto id and you can indeed use just one edmx file.

Darren

泅渡 2024-09-06 10:38:52

只要架构完全相同,您就确实需要 edmx 文件。只需更改连接字符串,一切都会无缝运行。虽然我不确定你是如何说当紧凑版不支持身份概念而完整的sql服务器支持身份概念时模式是相同的。因此,如果您使用特定于 sql server 的功能,而这些功能在紧凑型中不可用,那么您将收到运行时错误。

You do need the edmx file as long as the schema is exactly the same. just change the connectionstring and everything would work seamlessly. Though i am not sure how u are saying that schema is same when compact edition does not support identity concept and full blown sql server does. So if you are using features specific to sql server that's not available in compact, then you would get runtime errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文