Boolean Properties in EF Core(EF Core 中的布尔属性)
The example below illustrates how to implement Boolean Properties in an EF Core class.
下面的示例说明了如何在EF Core类中实现布尔属性。
C#
// 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:
您还可以通过模型编辑器中的以下属性指定标题和图像:
- IModelCommonMemberViewItem.CaptionForTrue
- IModelCommonMemberViewItem.CaptionForFalse
- IModelCommonMemberViewItem.ImageForTrue
- IModelCommonMemberViewItem.ImageForFalse