當(dāng) 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); }當(dāng)請求時,我收到以下錯誤https://localhost:44326/Products?$select=NameURI 中指定的查詢無效。在“GoodProduct”類型上找不到名為“Name”的屬性。如何在GoodProduct類中不創(chuàng)建 Name 屬性的情況下解決此問題?我正在將SelectExpandand設(shè)置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);
URI 中指定的查詢無效。在類型上找不到名為“Name”的屬性
函數(shù)式編程
2023-09-09 16:11:35