net6 - System.ComponentModel.DataAnnotations Attribute
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations; [MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{
}
public class CustomerMetaData
{
RangeAttribute 类
[Range(10, 1000,
ErrorMessage = "Value for {0} must be between {1} and {2}.")]
public object Weight; [Range(300, 3000)]
public object ListPrice; [Range(typeof(DateTime), "1/2/2004", "3/4/2004",
ErrorMessage = "Value for {0} must be between {1} and {2}")]
public object SellEndDate; DataTypeAttribute 类
// Add type information.
[DataType(DataType.EmailAddress)]
public object EmailAddress; RegularExpressionAttribute 类
// Allow up to 40 uppercase and lowercase
// characters. Use custom error.
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$",
ErrorMessage = "Characters are not allowed.")]
public object FirstName; // Allow up to 40 uppercase and lowercase
// characters. Use standard error.
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$")]
public object LastName;
}
DisplayFormatAttribute类
public class ProductMetaData
{ // Applying DisplayFormatAttribute
// Display the text [Null] when the data field is empty.
// Also, convert empty string to null for storing.
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[Null]")]
public object Size; // Display currency data field in the format $1,345.50.
[DisplayFormat(DataFormatString="{0:C}")]
public object StandardCost; // Display date data field in the short format 11/12/08.
// Also, apply format in edit mode.
[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:d}")]
public object SellStartDate;
}
DisplayColumnAttribute 类
[DisplayColumn("City", "PostalCode", false)]
public partial class Address
{
} [DisplayColumn("LastName")]
public partial class Customer
{
}
EnumDataTypeAttribute 类
public enum ReorderLevel
{
Zero = 0,
Five = 5,
Ten = 10,
Fifteen = 15,
Twenty = 20,
TwentyFive = 25,
Thirty = 30
} [MetadataType(typeof(ProductMD))]
public partial class Product
{
public class ProductMD
{
[EnumDataType(typeof(ReorderLevel))]
public object ReorderLevel { get; set; }
}
}
StringLengthAttribute 类
[MetadataType(typeof(ProductMetadata))]
public partial class Product
{ } public class ProductMetadata
{ [ScaffoldColumn(true)]
[StringLength(4, ErrorMessage = "The ThumbnailPhotoFileName value cannot exceed 4 characters. ")]
public object ThumbnailPhotoFileName; [ScaffoldColumn(true)]
[StringLength(4, ErrorMessage = "The {0} value cannot exceed {1} characters. ")]
public object PhotoFileName; }
net6 - System.ComponentModel.DataAnnotations Attribute的更多相关文章
- 对System.ComponentModel.DataAnnotations 的学习应用
摘要 你还在为了验证一个Class对象中很多数据的有效性而写很多If条件判断吗?我也同样遇到这种问题,不过,最近学了一项新的方法,让我不在写很多if条件做判断,通过给属性标注特性来验证数据规则,从此再 ...
- System.ComponentModel.DataAnnotations 冲突
项目从原来的.NET Framework4.0 升级到 .NET Framework4.5 编译报错. 查找原因是: Entity Framework 与 .net4.5 的 System.Compo ...
- System.ComponentModel.DataAnnotations.Schema.TableAttribute 同时存在于EntityFramework.dll和System.ComponentModel.DataAnnotations.dll中
Entity Framework 与 .net4.5 的 System.ComponentModel.DataAnnotations 都有 System.ComponentModel.DataAnno ...
- System.ComponentModel.DataAnnotations.Schema 冲突
System.ComponentModel.DataAnnotations.Schema 冲突 Entity Framework 与 .net4.5 的 System.ComponentModel.D ...
- System.ComponentModel.DataAnnotations 命名空间和RequiredAttribute 类
System.ComponentModel.DataAnnotations 命名空间提供定义 ASP.NET MVC 和 ASP.NET 数据控件的类的特性. RequiredAttribute 指定 ...
- 使用System.ComponentModel.DataAnnotations验证字段数据正确性
在.NET MVC 中,当页面提交model到Action的时候,自动填充ModelState.使用ModelState.IsValid进行方便快捷的数据验证,其验证也是调用命名空间System.Co ...
- 解决EntityFramework与System.ComponentModel.DataAnnotations命名冲突
比如,定义entity时指定一个外键, [ForeignKey("CustomerID")] public Customer Customer { get; set; } 编译时报 ...
- C# 特性 System.ComponentModel 命名空间属性方法大全,System.ComponentModel 命名空间的特性
目录: System.ComponentModel 特性命名空间与常用类 System.ComponentModel.DataAnnotations ComponentModel - Classes ...
- “CreateRiaClientFilesTask”任务意外失败。 未能加载文件程序集“System.ComponentModel.DataAnnot...
错误 77 “CreateRiaClientFilesTask”任务意外失败. System.Web.HttpException (0x80004005): 未能加载文件或程序集“System. ...
- 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问。
本地win7 本地正常,服务器win2008r2,服务器报错! 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问. 拒绝访问. 说明: 执行当前 W ...
随机推荐
- python实现两张图片拼接
纵向拼接 from PIL import Image def image_splicing(pic01, pic02): """ 图片拼接 :param pic01: 图 ...
- python怎么实现正确的浮点数四舍五入
round 以下示例展示对于结构相同的两组数据(1.03575000和1.03425000)保留小数后4位,使用内置函数round方法的输出结果,并不是需要的结果 print(round(1.0357 ...
- CSS控制背景图片100%自适应填充布局
原文地址:http://blog.csdn.net/wd4java/article/details/50537562 .personal_head { width: 100%; height: 35% ...
- java中List的浅拷贝与深拷贝
List浅拷贝 众所周知,list本质上是数组,而数组的是以地址的形式进行存储. 如上图将list A浅拷贝给list B,由于进行的是浅拷贝,所以直接将A的内容复制给了B,java中相同内容的数组指 ...
- spark2.0.1源码编译
一.编译源码步骤演示详解 . 编译spark环境要求 1.必须在linux系统下编译(以centos6.4为例) 2.编译使用的JDK版本必须是1.6以上(以JDK1.8为例) 3.编译需要使用Mav ...
- csv文件导入数据库中文乱码
在向数据库的表中导入csv数据时,出现了中文乱码的问题,解决办法是在选择编码格式时选择10008 (MAC - Simplified Chinese GB 2312)即可
- 【坑】 centos 7.6 使用ssh 秘钥登录遇到的问题
问题: 我在master1上面创建了一个ssh的秘钥文件,通过ssh-copy-id 传送四台主机,然后使用ansible all -m ping 发现有台机器就是有问题 这是怎么回事???一样的配置 ...
- C#笔记誊录<二>
c#编译器把源码编译成IL(中间)代码,再由CLR通过即时编译器把IL代码编译成本机机器语言(平台语言) www.webkaka.com//测试服务器的网速 ctrl+k+d 代码对其 CTRL+K+ ...
- SDN第二次实验
一.实验目的能够对Open vSwitch进行基本操作:能够通过命令行终端使用OVS命令操作Open vSwitch交换机,管理流表:能够通过Mininet的Python代码运行OVS命令,控制网络拓 ...
- K8S群集调度器
目录: 调度约束 Pod启动典型创建过程 调度过程 Predicate常见的算法 常见的优先级选项 指定调度节点 亲和性 键值运算关系 Pod亲和性和反亲和性 污点和容忍 污点 容忍 其他注意事项 c ...