如何在ASP.NET MVC EF中设置我的控制器场景? [英] How to setup my controllers scenario in ASP.NET MVC EF?

查看:61
本文介绍了如何在ASP.NET MVC EF中设置我的控制器场景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在DB中有桌子。



1.供应商

2.产品

3.公司

4.采购订单

5.收货通知



采购订单有外键

(i)Supplier_Id  (ii)Product_Id (iii)Company_Id。

我为供应商,产品,公司及其创建了服务类别。采购订单。

这些服务类帮助我使用Entity Framework执行CRUD操作,其中包含所有其他逻辑。



现在我' m混淆了如何创建我的控制器。我应该为每个实体创建单独的控制器,如SupplierController,ProductController,还是应该创建一个像StockController这样的控制器并管理该控制器中的所有操作。



我是什么尝试过:



我为每个实体创建了单独的控制器,但我不确定它是否是最好的方法。

解决方案

控制器是MVC严格对应于您的应用程序的视图,并在您的视图中执行您想要的操作。我认为控制器是指您实体的业务逻辑。如果您为每个实体创建了单独的业务类,那么这就是在实体框架中执行它的方法。应该是这样的。

随着控制器的发展,您可以参考任意数量的这些业务类来实现您想要的,没有技术限制。



欲了解更多信息,请访问 CP 制品

I have tables in DB.

1. Supplier
2. Product
3. Company
4. Purchase Order
5. Goods Receive Note

"Purchase Order" have the foreign keys
(i)Supplier_Id   (ii)Product_Id  (iii)Company_Id.
I have created service classes for Supplier, Product, Company & Purchase Order.
These service classes help me to perform CRUD operations using Entity Framework and all other logic is in it.

Now I'm confuse how to create my controllers. Should I create separate controllers for each entity like SupplierController, ProductController or should I create a single controller like StockController and manage all operations in this controller.

What I have tried:

I have created separate controllers for each entity but I'm not sure its the best way or not.

解决方案

"Controllers" is MVC strictly correspond to views of your application and do what you want in your view. I think by "controllers" you mean the business logic for your entities. If you have created separate business classes for each entity, then that is the way to do it in entity framework. That is how it should be.
As controllers go, you can refer to any number of these business classes to achieve what you want, there are no technical restrictions.

For more information, visit this CP article.


这篇关于如何在ASP.NET MVC EF中设置我的控制器场景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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