SQL Server CE 架构
我必须构建许多小型独立应用程序,这些应用程序可以复制到 USB 设备并从那里开箱即用。所以我正在考虑使用 WPF,它首先使用 EF 代码连接到 SQL Server CE 数据库。
我的问题是我应该使用什么架构。尽管这些应用程序是独立的,但我仍然希望将 UI 与域与数据分离,以实现层的清晰分离。但我也不想让它变得太复杂。
因此,我想要一个 UI 层 (WPF/MVVM),它使用底层域层(具有域逻辑的域对象)和存储库(首先使用 EF 代码)。
我的问题是:在这种情况下我应该使用什么模式来使 EF 工作?是否有一个示例演示如何在这种情况下实现 CRUD 操作?例如,我应该创建一个上下文并将其保持打开状态吗?或者我应该实现工作单元模式并将对象附加到其他上下文(如果需要)?
或者你会用完全不同的方式来做吗?
感谢您的建议!
I have to build a number of small independent applications, that can be copied to an USB device and run from there out of the box. So I was thinking to use WPF, that uses EF code first to connect to a SQL Server CE database.
My question is about what architecture I should use. Although the apps are standalone, I would still like to decouple UI from domain from data, to have a clean separation of layers. But I also don't want to make it too complex.
So, I want to have a UI layer (WPF/MVVM) that uses the underlying domain layer (domain objects with domain logic) and repositories (that use EF code first).
My question is: what pattern should I use to make EF work in this case? Is there somewhere an example that demonstrates how to implement CRUD operations in such scenario? For example, should I create one context and leave it open; or should I implement the unit of work pattern and attach objects to other context if needed?
Or would you do it in a totally different way?
Thanks for the advice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EF 上下文的开放时间应尽可能短。最好在 using 语句中使用它。
有一种称为 Attach 的方法,它将实体附加到上下文:
http://msdn .microsoft.com/en-us/library/bb896271.aspx
The EF context should be open for as short time as possible. Preferably use it within a using statement.
There is a method called Attach, which attachs entities to a context:
http://msdn.microsoft.com/en-us/library/bb896271.aspx