---
url: /nestjs-odata/api/generated/functions/buildContextUrl.md
---
# Function: buildContextUrl()

> **buildContextUrl**(`serviceRoot`, `entitySetName`, `select?`, `isSingleEntity?`): `string`

Defined in: [response/odata-context-url.builder.ts:18](https://github.com/cberd1509/nestjs-odata/blob/a42974292d62fe5da337a603d3b22d57c08cbf68/packages/core/src/response/odata-context-url.builder.ts#L18)

Builds the OData v4 @odata.context URL per spec section 10.

Format: {serviceRoot}/$metadata#{entitySetName}\[(field1,field2,...)]
Single-entity format: {serviceRoot}/$metadata#{entitySetName}/$entity

Per D-07: when $select has specific items (not all, not undefined),
a select projection suffix is appended.
Per D-05: when isSingleEntity is true, /$entity suffix is appended.

## Parameters

### serviceRoot

`string`

The OData service root path (e.g. '/odata')

### entitySetName

`string`

The name of the entity set (e.g. 'Products')

### select?

[`SelectNode`](../interfaces/SelectNode.md)

Optional SelectNode from the parsed query

### isSingleEntity?

`boolean`

When true, appends /$entity suffix for single-entity responses

## Returns

`string`
