Skip to main content
.NET 6.0+

Boolean Properties in EF Core

The example below illustrates how to implement Boolean Properties in an EF Core class.

// By default, a Boolean property is displayed via a CheckEdit control.
public virtual bool BooleanProperty { get; set; }

// To use a drop-down control, specify captions with the CaptionsForBoolValues attribute.
[CaptionsForBoolValues("TRUE", "FALSE")]
public virtual bool BooleanWithCaptions { get; set; }

// To display images in a drop-down, apply the ImagesForBoolValues attribute.
[ImagesForBoolValues("ImageForTrue", "ImageForFalse")]
[CaptionsForBoolValues("TRUE", "FALSE")]
public virtual bool BooleanWithImages { get; set; }

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

You can also specify captions and images via the following properties in the Model Editor:

See Also