[英]How should i return data in Web API Controller Methods?
I have a UI that needs lots of information. 我的UI需要大量信息。 Most of the information has been identified as separate entities in database.
大多数信息已被标识为数据库中的单独实体。 For example, displaying the details of an Employee.
例如,显示员工的详细信息。 The UI page might be Employee details with various sections regarding Employee Information such as Personal Details, Address, Contact details, Project Details etc.
UI页面可能是员工详细信息,其中包含有关员工信息的各个部分,例如个人详细信息,地址,联系方式,项目详细信息等。
So if we derive the entities for the same requirement, we will have following tables 因此,如果我们为相同的要求导出实体,我们将有以下表格
Employee 雇员
Address 地址
Contact 联系
Project 项目
We will be implementing repository pattern in DA layer, and ASP.Net Web API as our restful service layer. 我们将在DA层中实现存储库模式,并将ASP.Net Web API作为我们的静态服务层。
So, now if i need to display Employee details in the UI, what should be the best approach. 因此,现在,如果我需要在UI中显示Employee详细信息,那应该是最好的方法。 What i was thinking is mentioned below.
我在想什么在下面提到。
Approach 途径
There will be a single call to Web Api to get the Employee details. 将只需要致电Web Api即可获取员工详细信息。 Internally it will connect to database multiple times to get Employee details, Address information, Contact information, Projects information etc and populate into one EmployeeDetailsModel (a kind of viewmodel ) and return this as a JSON.
在内部,它将多次连接到数据库以获取Employee详细信息,地址信息,联系信息,项目信息等,并填充到一个EmployeeDetailsModel(一种viewmodel )中,并将其作为JSON返回。
Is this a good approach ? 这是一个好方法吗? If there is any other better approach please suggest
如果还有其他更好的方法,请提出建议
Going with your approach might prove as a poor user experience as users will wait for all the data to be assembled. 采用这种方法可能会导致不良的用户体验,因为用户将等待所有数据组装完毕。 I suggest you divide your web page into sections.
我建议您将网页分成几个部分。 First call employee data, and then on a different client event (say click the employee's project cell) call the employee's project detail (supposing it is another table)
首先调用员工数据,然后在另一个客户事件(例如,单击员工的项目单元格)上调用员工的项目明细(假设它是另一个表)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.