Share via


EdmProperty.Nullable Property

Definition

Gets a value indicating whether this EdmProperty can have a null value.

public bool Nullable { get; set; }
member this.Nullable : bool with get, set
Public Property Nullable As Boolean

Property Value

true if this EdmProperty can have a null value; otherwise, false.

Exceptions

Thrown if the setter is called when the EdmProperty instance is in ReadOnly state

Remarks

Nullability in the conceptual model and store model is a simple indication of whether or not the property is considered nullable. Nullability in the object model is more complex. When using convention based mapping (as usually happens with POCO entities), a property in the object model is considered nullable if and only if the underlying CLR type is nullable and the property is not part of the primary key. When using attribute based mapping (usually used with entities that derive from the EntityObject base class), a property is considered nullable if the IsNullable flag is set to true in the EdmScalarPropertyAttribute attribute. This flag can be set to true even if the underlying type is not nullable, and can be set to false even if the underlying type is nullable. The latter case happens as part of default code generation when a non-nullable property in the conceptual model is mapped to a nullable CLR type such as a string. In such a case, the Entity Framework treats the property as non-nullable even though the CLR would allow null to be set. There is no good reason to set a non-nullable CLR type as nullable in the object model and this should not be done even though the attribute allows it.

Applies to