[英]Return different Dto using same repository method with Nhibernate
I have a Web API that request a GET method that can return based in the same parameters different results (Dtos) example: 我有一个Web API,它请求一个GET方法,该方法可以根据相同的参数返回不同的结果(Dtos)示例:
GET - http://localhost/books/searchAll?Detailed=true `
Returns DTO 1 ["Id":1,"Date": 01/01/2014]
GET - http://localhost/books/searchAll?Detailed=false `
Returns DTO 2 ["Id":1]
What is the best approach to deal with this situation : 解决这种情况的最佳方法是什么:
Should I create a http response with one Dto that includes two different list of results : 我是否应该使用一个Dto创建一个包含两个不同结果列表的http响应:
Public Class ResultList
{
Public List<Dto> DtoList1{get;set;}
Public List<Dto2> DtoList2{get;set;}
}
Or with just one dto list that return a dynamic list 或仅具有一个返回动态列表的dto列表
Public Class ResultList
{
Public List<dynamic> DtoList{get;set;}
}
Or other solution ? 还是其他解决方案?
Regards 问候
If you are returning two different resources (or classes or types) I would definitely go for having two different methods but also they would serve two different URLs, let's say for eg. 如果您要返回两个不同的资源(或类或类型),那么我肯定会使用两个不同的方法,但是它们将提供两个不同的URL,例如。 Search and searchDetail.
搜索和searchDetail。
If you re returning the same resource but one time full and the other partially then I would have one method, use the detail parameter you suggested but I would return the same dto class sometimes with all it's attributes wit values and others only with its minimum attributes with value. 如果您返回相同的资源,但一次又一次,而另一部分则是全部,那么我将有一个方法,使用您建议的detail参数,但有时会返回相同的dto类,其中包含所有属性wit值,而其他则仅返回其最小属性具有价值。 After all you are returning a json object which can have dynamic attributes without any problem.
毕竟,您将返回一个JSON对象,该对象可以具有动态属性而没有任何问题。
That's what I think. 那就是我所想的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.