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:
displayName
was given a value by the service even though no value was provided by the clientfoo
has the default value as specified by itsDefaultValue
attribute in the CSDLbar
has the default value as specified by itsDefaultValue
attribute 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:
displayName
cannot be set tonull
because 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:
displayName
can 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:
foo
can be set tonull
because 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:
foo
can 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:
bar
cannot be set tonull
because 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:
bar
can 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:
displayName
isn't required to create a newservicePrincipal
, but it can be provided; this is orthogonal to whether or not the property hasNullable="true"
orNullable="false"
.foo
has the default value as specified by itsDefaultValue
attribute in the CSDLbar
has the default value as specified by itsDefaultValue
attribute 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:
displayName
isn't required to create a newservicePrincipal
, but it can be provided; it cannot be provided asnull
because 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:
displayName
was given a value by the service even though no value was provided by the clientfoo
isn't required to create a newservicePrincipal
, but it can be provided; this is orthogonal to whether or not the property hasNullable="true"
orNullable="false"
.bar
has the default value as specified by itsDefaultValue
attribute 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:
displayName
was given a value by the service even though no value was provided by the clientfoo
isn't required to create a newservicePrincipal
, but it can be provided; because the property hasNullable="true"
, anull
value can be provided for it.bar
has the default value as specified by itsDefaultValue
attribute 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:
displayName
was given a value by the service even though no value was provided by the clientfoo
has the default value as specified by itsDefaultValue
attribute in the CSDLbar
isn'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:
bar
isn't required to create a newservicePrincipal
, but it can be provided; it cannot be provided asnull
because the property was marked withNullable="false"