MVVM在哪里放置数据访问层? [英] MVVM where to put Data Access Layer?

查看:105
本文介绍了MVVM在哪里放置数据访问层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调查WPF的MVVM设计模式。但是不知道在哪里放置数据Acess代码?



在一些示例中,我已经看过,数据访问直接在ViewModel中执行。在ViewModel中将类似linq的东西放到sql中似乎很奇怪?其他例子有一个独立的数据访问项目,这似乎更像吗?



这是一般的做法吗?我觉得我在这里缺少一些东西!



谢谢

解决方案

我会添加另一个层,实质上你想要的是一个数据工厂。您要创建一组将为您的CRUD到数据库的类,并将干净的POCO对象返回给ViewModel。



一个很好的例子是 Nerd Dinner book 。它涵盖MVC不是MVVM,但是模式非常相似,他们访问该解决方案中的数据的方式将是很好的起点。



希望这有帮助。 b $ b

I am investigating WPF's MVVM design pattern. But am unsure where to put the Data Acess code?

In some examples I have looked at, data access is performed directly in the ViewModel. It seems odd to put something like linq to sql in the ViewModel? Other examples have a seperate project for Data Access, this seems more like it?

Is this there a general approach? I feel like I am missing something here!

Thanks

解决方案

I would add another layer, essentially what you want is a data factory. You want to create a set of classes that will CRUD to the database for you and return clean POCO objects to the ViewModel.

A good example to look at would the Nerd Dinner book. It covers MVC not MVVM but the patterns are very similar and the way they access data in that solution would be good starting point.

Hope this helps.

这篇关于MVVM在哪里放置数据访问层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆