C# OData响应将原语值保留在json的根级别
我将OData实现为一个C# OData响应将原语值保留在json的根级别,c#,serialization,odata,C#,Serialization,Odata,我将OData实现为一个GET调用,以从较大的返回对象扩展单个对象类型,从而降低序列化成本。不幸的是,ODataQueryOptions没有以我期望的格式返回序列化对象。也就是说,当我没有在展开中指定任何基元类型的值时,它会留下在对象的“根”级别(序列化时)定义的基元类型的值 服务器端代码: public async Task<HttpResponseMessage> RetrieveDocument(int id, ODataQueryOptions<Contract.Est
GET
调用,以从较大的返回对象扩展单个对象类型,从而降低序列化成本。不幸的是,ODataQueryOptions
没有以我期望的格式返回序列化对象。也就是说,当我没有在展开中指定任何基元类型的值时,它会留下在对象的“根”级别(序列化时)定义的基元类型的值
服务器端代码:
public async Task<HttpResponseMessage> RetrieveDocument(int id, ODataQueryOptions<Contract.EstimateDocument> oDataQuery)
{
var cacheKey = EstimateDocumentCacheKeyGenerator.GetCacheKeyForEstimateDocument(id, CurrentUserSession.UserOrgCode, oDataQuery.RawValues.Filter, oDataQuery.RawValues.Expand);
string serializedEstimateDocument;
if (!_serializedEstimateDocumentCache.TryGet(cacheKey, out serializedEstimateDocument))
{
var estimateDocument = _estimateDocumentService.RetrieveDocument(CurrentUserSession, id);
if (oDataQuery.SelectExpand != null||
oDataQuery.Filter != null)
{
IQueryable<Contract.EstimateDocument> estimateDocumentQueryable =
new List<Contract.EstimateDocument>() {estimateDocument}.AsQueryable();
var result = oDataQuery.ApplyTo(estimateDocumentQueryable);
serializedEstimateDocument = CacheResponseObject(result, cacheKey);
}
else
{
serializedEstimateDocument = CacheResponseObject(estimateDocument, cacheKey);
}
}
var responseMessage = CreateMessage(serializedEstimateDocument, HttpStatusCode.OK);
//LogApiCall(id, responseMessage);
return responseMessage;
}
预期:
[{
"psudoObject": { /*contents*/ }
}]
是否有OData设置可以更改以获得预期结果?如果做不到这一点,是否有一种方法可以删除那些不涉及更改序列化对象字符串的对象
[{
"psudoObject": { /*contents*/ }
}]