使用存储库模式时我们是否需要重新创建模型类
我正在将 LinqtoSQL 用于 WPF MV-VM 应用程序,因为我将来可能想从 LinqtoSql 更改为其他东西,例如实体框架或 Subsonic 等,因此我发现存储库模式很有帮助,
我的问题是如何做我创建模型类,假设我在数据库中有一个表,我知道我不能使用 LINQtoSQL 生成的类作为模型类,如果我这样做,那么我将变得依赖于 LinqtoSQL,这反过来又会剥夺我必须实现存储库模式,这是否意味着我需要为所有实体类拥有自己的自定义类?
I'm using the LinqtoSQL for a WPF M-V-VM application, as I might want to change from LinqtoSql to something else in the future, like Entity framework or Subsonic etc, thus I found repository pattern to be helpful,
My question is how do I create the model classes, suppose I have an table in the database, I understand that I cannot use the LINQtoSQL generated Class as the model class, if I do, then I would become dependent on LinqtoSQL, which inturn would take away the independence that I would have of implementing the repository pattern, does that mean that I would need to have my own custom classes for all entity classes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
天哪,不。你为什么要这样对自己?
您已经在 ViewModel 中复制了这么多内容,为什么还要添加另一层复制来获得如此小的收益,特别是考虑到 L2S 可以使用普通的 ol' clr 类型?
我认为 WCF 服务和 ORM 类型的服务契约都是我的模型。仅仅因为它不驻留在 *.Model 命名空间中并不意味着什么。
如果您觉得需要这个润滑层,请将该层作为您的 ViewModel。这就是他们存在的目的。
Good lord, no. Why would you do that to yourself?
You've already got to duplicate so much in your ViewModels, why would you add another layer of duplication for so little gain, especially considering L2S can use plain ol' clr types?
I consider both my service contracts from WCF services and ORM types to be my model. Just because it doesn't reside in a *.Model namespace doesn't mean a thing.
If you feel like you need this lubricating layer, let that layer be your ViewModels. That's what they are there for.
是的,这意味着您需要为所有实体类实现您自己的自定义类。这很痛苦,但这就是目前的情况。
请参阅 这个答案 有关该主题的更多信息以及一些可能的补救措施。
Yes, it means that you need to implement you own custom classes for all entity classes. It's a pain, but that's the current state of things.
See this SO answer for more information on the subject, and some possible remedies.