You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何构建OData GET请求仅获取指定的三个字段

Fixing Your OData GET Request to Fetch Only Needed Fields

Got it, let's sort out that OData request so you only get the three fields you care about! The key here is that you can nest $select inside $expand to specify exactly which fields you want from the related Franchise entity, instead of pulling the entire object.

Correct OData Request

Use this request to fetch just PostalCode, FranchiseId, and the nested FranchiseeName:

#url#&$select=PostalCode,FranchiseId&$expand=Franchise($select=FranchiseeName)

What This Does

  • $select=PostalCode,FranchiseId: Tells the API to only return these two top-level fields.
  • $expand=Franchise($select=FranchiseeName): Expands the Franchise relation, but restricts it to only include the FranchiseeName field (no extra data like CreatedDateTime or City).

Expected Response Structure

With this request, the API will return a structure like this (note the nested Franchise object with only your desired field):

{
  "PostalCode": "48103",
  "FranchiseId": 397,
  "Franchise": {
    "FranchiseeName": "Appliance Inc - Ann Arbor, MI - MLY 1001"
  }
}

Getting FranchiseeName at the Top Level (If Supported)

If you want FranchiseeName to be a top-level field (matching your exact desired output), some OData 4.0 services support the $apply operator to project nested fields up. Try this request if your API allows it:

#url#&$apply=compute(FranchiseeName as Franchise/FranchiseeName)&$select=PostalCode,FranchiseId,FranchiseeName

If your API doesn't support $apply, you'll need to do a quick transformation on the client side to extract Franchise.FranchiseeName and move it to the top level of the object.

内容的提问来源于stack exchange,提问作者DoArNa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:26:42