当 odata 请求包含 $select 查询时,我返回不同的实体。这是我的获取方法:
public IHttpActionResult Get(ODataQueryOptions<Product> queryOptions, CancellationToken cancellationToken)
{
if (Context == null)
Context = MainContext.CreateInstance();
var products = Context.GetEntities<Product>();
if (queryOptions.RawValues?.Select != null)
{
var goodProducts = MakeGoodProductList(products); // Type of entity is GoodProduct
return Ok(goodProducts);
}
return Ok(products);
}
当请求时,我收到以下错误https://localhost:44326/Products?$select=Name
URI 中指定的查询无效。在“GoodProduct”类型上找不到名为“Name”的属性。
如何在GoodProduct类中不创建 Name 属性的情况下解决此问题?
我正在将SelectExpandand设置Select为 null ODataQueryOptions,ODataRawQueryOptions但它们没有帮助:
typeof(ODataQueryOptions).GetProperty(nameof(queryOptions.SelectExpand)).SetValue(queryOptions, null, null);
typeof(ODataRawQueryOptions).GetProperty(nameof(queryOptions.rawQueryOptions.Select)).SetValue(queryOptions.rawQueryOptions, null, null);
郎朗坤
相关分类