EdmProperty.Nullable Property

 

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

Namespace:   System.Data.Entity.Core.Metadata.Edm
Assembly:  EntityFramework (in EntityFramework.dll)

public bool Nullable { get; set; }

Property Value

Type: System.Boolean

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

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.