如何在MVC中使用单个控制器编写服务 [英] How do I write a service with a single controller in MVC

查看:51
本文介绍了如何在MVC中使用单个控制器编写服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai All,我正在MVC做一个项目。我试图使用单个代码将数据保存在多个表中。真实情况:



我有一张学生桌和老师桌。我想使用相同的代码来保存表中的数据。有没有想法在重复使用代码的情况下将数据保存在两个表中?



先谢谢。

Hai All, I am doing a project in MVC. I am trying to use the a single code to save the data in multiple tables. The real situation:

I have a student table and Teacher table. I want to use the same code to save the data in both the tables. Any idea to save the data in both the tables with the reusing of the code??

Thanks in Advance.

推荐答案

编写context.SaveChanges所在的服务并从控制器调用该服务。

这也会减少耦合。有一个Add实体方法和Context.SaveChanges()一次

希望这有帮助

谢谢

:)
You write the service where the context.SaveChanges would be present & get that service called from your controller.
This will also reduce coupling. Have the Add entity method and Context.SaveChanges() once
Hope this helps
Thanks
:)


这篇关于如何在MVC中使用单个控制器编写服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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