代码示例: 在实体类中,使用[System.ComponentModel.DataAnnotations.Schema.NotMapped]来限制某个bool类型的属性只能设置为true。
public class MyEntity {
public int Id { get; set; }
public string Name { get; set; }
[NotMapped]
public bool OnlyAllowTrue { get; set; }
}
在实体类中,使用[System.ComponentModel.DataAnnotations]来限制某个bool类型的属性只能设置为true。
public class MyEntity {
public int Id { get; set; }
public string Name { get; set; }
[Range(typeof(bool), "true", "true")]
public bool OnlyAllowTrue { get; set; }
}