简体   繁体   English

我有一个 wpf mvvm 应用程序,我应该把数据库或套接字放在哪里?

[英]I have a wpf mvvm application, where do I put Database or Sockets?

as I explained in the title I have a wpf app with only one View.正如我在标题中所解释的,我有一个只有一个视图的 wpf 应用程序。 The model is Note.型号是注。 In the view you can add notes.在视图中,您可以添加注释。 Those notes must be sended to a sockets server or saved on a Database, my question is: where do I put the code related to the action of saving notes?这些笔记必须发送到套接字服务器或保存在数据库中,我的问题是:与保存笔记操作相关的代码放在哪里? In model, viewmodel or in another class?在模型、视图模型或另一个类中?

This question may be trivial, but I have just started up with wpf+mvvm and I am a bit lost.这个问题可能是微不足道的,但是我刚开始用wpf+mvvm,有点迷茫。

Thanks for your help :)谢谢你的帮助 :)

Saving or loading model data would be located in the model or a class used by the model.保存或加载模型数据将位于modelmodel使用的类中。 That would be the first M of 那将是的第一个M

viewmodel is the inter-mediator between view and model. viewmodel 是视图和模型之间的中介。 viewmodel is the place where you code the functionality you want in your application whereas model is the core class describing the entities of your application. viewmodel 是您在应用程序中编写所需功能的地方,而模型是描述应用程序实体的核心类。

I tend to separate anything to do with database accessing to different classes, or even another project and referencing those classes there.我倾向于将与数据库访问不同类或什至另一个项目并在那里引用这些类有关的任何事情分开。 depending of the size of your project its a good way to make maintaining the database actions.根据项目的大小,这是维护数据库操作的好方法。 it also allows you to generalize the database actions.它还允许您概括数据库操作。 in the end its up to you where you want to place it.最后取决于你想把它放在哪里。

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

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