我正在研究ServiceStack对AutoQuery的部分响应,代码片段如下:
public class SalesOrderServices : MyService
{
Utilities.RequestUtilities utilities = new Utilities.RequestUtilities();
public object Any(SalesOrdersGet request)
{
String qString = GetSelectString(base.Request);
var q = AutoQuery.CreateQuery(request, Request.GetRequestParams());
if (!qString.IsNullOrEmpty())
{
q.Select(qString);
}
return AutoQuery.Execute(request, q);
}
继承了MyService
namespace WombatWS.ServiceInterface.Sales
{
public class MyService : Service
{
public IAutoQuery AutoQuery { get; set; }
public String GetSelectString(IRequest request)
{
String qString = "";
if (!request.QueryString["fields"].IsNullOrEmpty())
{
String sFields = request.QueryString["fields"].ToString();
String[] properties = sFields.Split(',');
foreach (String s in properties)
{
if (!s.Equals(properties.Last().ToString()))
{
qString += s + ",";
}
else
{
qString += s;
}
}
}
return qString;
}
}
}
我注意到除了我放入?field={field1},{field2}...
的有趣字段之外,不需要的DateTime将按原样返回,以及所有int,GUID类型也将返回为0,0000-000000000-0000- 00000的东西。如何摆脱它们?感谢。