A nullable property means only that the property may have null as a value; the "nullability" of a property does not say anything about how a value is set into a property.
For example, a non-nullable property is not required to create a new instance of an entity.
It only means that the property will have a value when it is retrieved.
In the case that no value is provided when the entity is created, this means that the service will create one; this value can be specified with the DefaultValue attribute, but if the value is contextual and determine at request time, then the property can both be non-nullable and have no DefaultValue specified.
Below are some examples of nullable and non-nullable properties.
<EntitySet Name="servicePrincipals" Type="self.servicePrincipal" />
...
<EntityType Name="servicePrincipal">
<Key>
<PropertyRef Name="id" />
</Key>
<Property Name="id" Type="Edm.String" Nullable="false" />
<Property Name="appId" Type="Edm.String" Nullable="false" /> <!--required for creation-->
<Property Name="displayName" Type="Edm.String" Nullable="false" />
<Property Name="foo" Type="Edm.String" Nullable="true" DefaultValue="testval" />
<Property Name="bar" Type="Edm.String" Nullable="false" DefaultValue="differentvalue" />
...
</EntityType>POST /servicePrincipals
400 Bad Request
{
"error": {
"code": "badRequest",
"message": "The 'appId' property is required to create a servicePrincipal."
}
}POST /servicePrincipals
{
"appId": "00000000-0000-0000-0000-000000000001"
}
201 Created
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": "some application name",
"foo": "testval",
"bar": "differentvalue",
...
}Notes:
displayNamewas given a value by the service even though no value was provided by the clientfoohas the default value as specified by itsDefaultValueattribute in the CSDLbarhas the default value as specified by itsDefaultValueattribute in the CSDL
PATCH /servicePrincipals/00000000-0000-0000-0000-000000000001
{
"displayName": null
}
400 Bad Request
{
"error": {
"code": "badRequest",
"message": "null is not a valid value for the property 'displayName'; 'displayName' is not a nullable property."
}
}Notes:
displayNamecannot be set tonullbecause it has be marked withNullable="false"in the CSDL.
PATCH /servicePrincipals/00000000-0000-0000-0000-000000000001
{
"displayName": "a non-generated display name"
}
200 OK
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": "a non-generated display name",
"foo": "testval",
"bar": "differentvalue",
...
}Notes:
displayNamecan be set to any value other thannull- The response body here is provided for clarity, and is not part of the guidance itself. The OData v4.01 standard states that the workload can decide the behavior.
PATCH /servicePrincipals/00000000-0000-0000-0000-000000000001
{
"foo": null
}
200 OK
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": "a non-generated display name",
"foo": null,
"bar": "differentvalue",
...
}Notes:
foocan be set tonullbecause it has be marked withNullable="true"in the CSDL.- The response body here is provided for clarity, and is not part of the guidance itself. The OData v4.01 standard states that the workload can decide the behavior.
PATCH /servicePrincipals/00000000-0000-0000-0000-000000000001
{
"foo": "something other than testval"
}
200 OK
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": "a non-generated display name",
"foo": "something other than testval",
"bar": "differentvalue",
...
}Notes:
foocan be set tosomething other than testval- The response body here is provided for clarity, and is not part of the guidance itself. The OData v4.01 standard states that the workload can decide the behavior.
PATCH /servicePrincipals/00000000-0000-0000-0000-000000000001
{
"bar": null
}
400 Bad Request
{
"error": {
"code": "badRequest",
"message": "null is not a valid value for the property 'bar'; 'bar' is not a nullable property."
}
}Notes:
barcannot be set tonullbecause it has be marked withNullable="false"in the CSDL.
PATCH /servicePrincipals/00000000-0000-0000-0000-000000000001
{
"bar": "a new bar"
}
200 OK
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": "a non-generated display name",
"foo": "something other than testval",
"bar": "a new bar",
...
}Notes:
barcan be set toa new bar- The response body here is provided for clarity, and is not part of the guidance itself. The OData v4.01 standard states that the workload can decide the behavior.
POST /servicePrincipals
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": "a different name"
}
201 Created
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": "a different name",
"foo": "testval",
"bar": "differentvalue",
...
}Notes:
displayNameisn't required to create a newservicePrincipal, but it can be provided; this is orthogonal to whether or not the property hasNullable="true"orNullable="false".foohas the default value as specified by itsDefaultValueattribute in the CSDLbarhas the default value as specified by itsDefaultValueattribute in the CSDL
POST /servicePrincipals
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": null
}
400 Bad Request
{
"error": {
"code": "badRequest",
"message": "null is not a valid value for the property 'displayName'; 'displayName' is not a nullable property."
}
}Notes:
displayNameisn't required to create a newservicePrincipal, but it can be provided; it cannot be provided asnullbecause the property was marked withNullable="false"
POST /servicePrincipals
{
"appId": "00000000-0000-0000-0000-000000000001",
"foo": "a foo value on creation"
}
201 Created
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": "some application name",
"foo": "a foo value on creation",
"bar": "differentvalue",
...
}Notes:
displayNamewas given a value by the service even though no value was provided by the clientfooisn't required to create a newservicePrincipal, but it can be provided; this is orthogonal to whether or not the property hasNullable="true"orNullable="false".barhas the default value as specified by itsDefaultValueattribute in the CSDL
POST /servicePrincipals
{
"appId": "00000000-0000-0000-0000-000000000001",
"foo": null
}
201 Created
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": "some application name",
"foo": null,
"bar": "differentvalue",
...
}Notes:
displayNamewas given a value by the service even though no value was provided by the clientfooisn't required to create a newservicePrincipal, but it can be provided; because the property hasNullable="true", anullvalue can be provided for it.barhas the default value as specified by itsDefaultValueattribute in the CSDL
POST /servicePrincipals
{
"appId": "00000000-0000-0000-0000-000000000001",
"bar": "running out of ideas for value names"
}
201 Created
{
"appId": "00000000-0000-0000-0000-000000000001",
"displayName": "some application name",
"foo": "testval",
"bar": "running out of ideas for value names",
...
}Notes:
displayNamewas given a value by the service even though no value was provided by the clientfoohas the default value as specified by itsDefaultValueattribute in the CSDLbarisn't required to create a newservicePrincipal, but it can be provided; this is orthogonal to whether or not the property hasNullable="true"orNullable="false".
POST /servicePrincipals
{
"appId": "00000000-0000-0000-0000-000000000001",
"bar": null
}
400 Bad Request
{
"error": {
"code": "badRequest",
"message": "null is not a valid value for the property 'bar'; 'bar' is not a nullable property."
}
}Notes:
barisn't required to create a newservicePrincipal, but it can be provided; it cannot be provided asnullbecause the property was marked withNullable="false"