MVC应用程序中的服务层 [英] service layer in MVC application

查看:112
本文介绍了MVC应用程序中的服务层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我如何使用实体框架和WCF在我的MVC应用程序中实现服务层.这个想法是抽象数据库细节.

谢谢

Hi,

How can i implement a service layer in my MVC application using Entity framework and WCF. The idea is to abstract database detail.

Thanks

推荐答案

如果您使用的是EF,则实际上并不需要那种抽象,但是如果需要,则可以创建一个DLL,然后执行EF在其中映射,并将所有模型类也放置在其中,因为它们将映射到您的数据库.我认为这很麻烦,但是您可以那样做,只需要在DLL中提供通过EF更改DB的所有代码即可.

确实,EF会为您执行此操作,它通过强类型化的模型类提供数据库访问,并向您隐藏DB层.
If you''re using EF then that sort of abstraction is not really needed, but if you want it, then you create a DLL, do your EF mappings in there, and place all your model classes in there, too, as they will map to your DB. I think it''s messy, but you can do it that way, and just provide all the code that changes the DB through EF inside that DLL.

Really, EF is doing that for you, it provides database access through strongly typed model classes and hides the DB layer from you.


看看 ^ ]


这篇关于MVC应用程序中的服务层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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