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的更多相关文章

  1. 对System.ComponentModel.DataAnnotations 的学习应用

    摘要 你还在为了验证一个Class对象中很多数据的有效性而写很多If条件判断吗?我也同样遇到这种问题,不过,最近学了一项新的方法,让我不在写很多if条件做判断,通过给属性标注特性来验证数据规则,从此再 ...

  2. System.ComponentModel.DataAnnotations 冲突

    项目从原来的.NET Framework4.0 升级到 .NET Framework4.5 编译报错. 查找原因是: Entity Framework 与 .net4.5 的 System.Compo ...

  3. System.ComponentModel.DataAnnotations.Schema.TableAttribute 同时存在于EntityFramework.dll和System.ComponentModel.DataAnnotations.dll中

    Entity Framework 与 .net4.5 的 System.ComponentModel.DataAnnotations 都有 System.ComponentModel.DataAnno ...

  4. System.ComponentModel.DataAnnotations.Schema 冲突

    System.ComponentModel.DataAnnotations.Schema 冲突 Entity Framework 与 .net4.5 的 System.ComponentModel.D ...

  5. System.ComponentModel.DataAnnotations 命名空间和RequiredAttribute 类

    System.ComponentModel.DataAnnotations 命名空间提供定义 ASP.NET MVC 和 ASP.NET 数据控件的类的特性. RequiredAttribute 指定 ...

  6. 使用System.ComponentModel.DataAnnotations验证字段数据正确性

    在.NET MVC 中,当页面提交model到Action的时候,自动填充ModelState.使用ModelState.IsValid进行方便快捷的数据验证,其验证也是调用命名空间System.Co ...

  7. 解决EntityFramework与System.ComponentModel.DataAnnotations命名冲突

    比如,定义entity时指定一个外键, [ForeignKey("CustomerID")] public Customer Customer { get; set; } 编译时报 ...

  8. C# 特性 System.ComponentModel 命名空间属性方法大全,System.ComponentModel 命名空间的特性

    目录: System.ComponentModel 特性命名空间与常用类 System.ComponentModel.DataAnnotations ComponentModel - Classes ...

  9. “CreateRiaClientFilesTask”任务意外失败。 未能加载文件程序集“System.ComponentModel.DataAnnot...

    错误  77  “CreateRiaClientFilesTask”任务意外失败.  System.Web.HttpException (0x80004005): 未能加载文件或程序集“System. ...

  10. 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问。

    本地win7 本地正常,服务器win2008r2,服务器报错! 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问. 拒绝访问. 说明: 执行当前 W ...

随机推荐

  1. JavaSE总结(2)

    控制语句idea.方法重载控制语句1.顺序结构从上到下从左到右依次执行2.判断结构    a.if(判断表达式){        语句体;    }    b.if(判断表达式){        语句 ...

  2. Django基础(1)

    一.开发模式 MVC模式: model:数据库 view:前端展示 controller:逻辑控制 MTV模式(Django): model:数据库 view:逻辑控制 template:前端展示(模 ...

  3. ABAP 委外采购收货调用过账bapi

    相关的表: ekko:采购凭证抬头表 用于判断是否委外 ekpo:采购凭证行项目表 用于判断是否委外以及委外采购的数量 resb:获取委外采购单中bom的相应预留 mseg:获取已经委外原材料出库给供 ...

  4. Centos 升级glibc 亲测好用

    wget http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz  tar zxf glibc-2.18.tar.gz cd glibc-2.18/ mkdir ...

  5. Java-集合概要

    集合概要 Java集合类存放于 java.util 包中,是一个用来存放对象的容器. 集合的两个主要接口是 Collection接口 和 Map 接口. 图片来源:菜鸟教程 集合的优点 区别 集合 数 ...

  6. element table组件列表固定列后横向滚动条的问题

    使用el-table的fixed属性固定表格列的时候滚动条被固定列覆盖部分无法拖动 可以使用下面配置来解决 .el-table__fixed { height: auto !important; // ...

  7. db2存储过程 动态拼接sql 、输出数据集示例

    *****部分都是表名.因为隐私关系,替换为*了. 1 CREATE PROCEDURE "BI_DM"."SP_GCYP_REPORT" ( 2 startd ...

  8. 软件工程日报九——SQLite的安装与配置

    安卓stuio的数据库连接需要SQLite,现在进行安装与配置 一进官网下载sqlite-dll-win32-x86.zip和sqlite-tools-win32-x86.zip 二.在下载目录进行解 ...

  9. 安防视频监控系统前端摄像机——DSP与SOC摄像机

    一.DSP摄像机 DSP(Digital Signal Processing)即数字信号处理,它是利用数字计算机或专用数字信号处理设备,以数值计算的方法对信号进行采集.变换.综合.估值.识别等加工处理 ...

  10. const char* str和const char str[]的区别

    首先,字符串常量是存储在flash中的.假设字符串常量在flash中的地址是0x8003fb8. 第一种方式,str等价于str的内存单元的地址,str的内存单元存储着字符串常量的地址 第二种方式,s ...