WCF数据协定用作MVC模型。 [英] WCF data contract used as MVC model.

查看:61
本文介绍了WCF数据协定用作MVC模型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,

我在设计MVC和WCF应用程序时遇到了一些困惑。我们可以在WCF中使用Data Contract作为MVC中的域模型,这样就不用重复Model.Can的代码了。建议我是否使用Data Contract作为WCF Model.Suggest做这种情况的最佳方法。



谢谢

Dinesh Sharma

Hi Experts,
I have some confusion while design MVC and WCF application.Can we use Data Contract in WCF as Domain Model in MVC so that not to repeat the code of Model.Can you please suggest me whether use Data Contract as WCF Model.Suggest best approach to do this kind of scenario.

Thanks
Dinesh Sharma

推荐答案

你可以,但它有点脆弱。如果wcf模型发生任何变化,使用该模型的所有内容都需要适应。但是如果你为MVC使用另一个模型,你只需要改变wcf和mvc模型之间的映射。

例如,在几个视图中使用wcf模型中的Name。现在,wcf模型将Name更改为ProductName,您需要将每个Name引用更改为ProductName,而不是仅更改mvc模型中的映射。因为两个模型看起来都很相似,所以你可以使用AutoMapper在模型之间轻松映射。



祝你好运!
You could, but it is kind of fragile. If anything changes in the wcf model, everything using that model needs to adapt to that. But if you use another model for MVC you just have to only change the mapping between wcf and the mvc model.
For example, using Name from the wcf model in several views. Now the wcf model changes Name to ProductName and you need to change every Name reference to ProductName instead of only changing the mapping in your mvc model. Because both models will look alike, you can use AutoMapper for easy mapping between the models.

Good luck!


这篇关于WCF数据协定用作MVC模型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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