WP7 Mango 上是否有中央数据上下文?
我现在开始将一个应用程序迁移到 WP7 Mango。原因之一是数据库支持:-)
从技术上讲,数据库的事情非常清楚。但我有点不确定应该把数据上下文放在哪里。我看到主要的两个选项:
- 所有内容的全局数据上下文
- 每个应用程序功能的单独数据上下文实例
我想对此有一些想法。
谢谢!
I'm starting to migrate one app to WP7 Mango now. One of the reasons is the database support :-)
Technically the database thing is really clear. But I'm a bit unsure where should I put my datacontext. I see primary two options:
- global datacontext for everything
- a separate datacontext instance per app feature
I would like to have some thoughts on that.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SQLite2CE 工具附带的演示可能会对您有所帮助,因为它提供了如何使用数据上下文和 ViewModel 的示例。访问 http://sqlite2ce.codeplex.com/ 并下载包,该页面上的链接文章也会成为一个帮助。另外,如果您尚未从 SQLite 转换数据库,那么该工具也将帮助您完成此操作。
如果您看一下演示,就会发现有一个 MainViewModel(设置为应用程序的 MainPage.xaml 的数据上下文),其中包含每个引用的数据类的 ObservableCollection。第二个 ViewModel 用于从数据库编译一组自定义数据,但仍通过 MainViewModel 中的 ObservableCollection 进行引用。这样,您希望在 XAML 中绑定的每个控件只需引用相应 ObservableCollection 对象中的列。
The demo included with the SQLite2CE tool might help you in that it gives an example of how to use datacontext and ViewModels. Visit http://sqlite2ce.codeplex.com/ and download the package, the linked articles on this page will also be a help. As a bonus, if you haven't yet converted your database from SQLite then the tool will help you with that as well.
If you take a look at the demo there's a MainViewModel (set as the datacontext of the application's MainPage.xaml) which contains an ObservableCollection for each referenced class of data. A second ViewModel is used to compile a custom set of data from the database but is still referenced though an ObservableCollection in MainViewModel. This way each control you wish to bind in XAML only needs to reference a column within the appropriate ObservableCollection object.
目前我将使用多个数据上下文来实现不同的功能。我将尝试通过单例模式使用单个模式。这导致了一些异常,因为您需要同步 SubmitChanges() 调用 - 特别是在使用不同线程的情况下。
At the moment I'm would use multiple datacontext for the different features. I'll tried to use a single one through the singleton pattern. This caused some exceptions because you'll need to syncronize the SubmitChanges() calls - especially if different threads are used.