1. using System;
  2. using System.Web.DynamicData;
  3. using System.ComponentModel.DataAnnotations;
  4.  
  5. [MetadataType(typeof(CustomerMetaData))]
  6. public partial class Customer
  7. {
  8. }
  9. public class CustomerMetaData
  10. {
  11.   RangeAttribute
  12. [Range(10, 1000,
  13. ErrorMessage = "Value for {0} must be between {1} and {2}.")]
  14. public object Weight;
  15.  
  16. [Range(300, 3000)]
  17. public object ListPrice;
  18.  
  19. [Range(typeof(DateTime), "1/2/2004", "3/4/2004",
  20. ErrorMessage = "Value for {0} must be between {1} and {2}")]
  21. public object SellEndDate;
  22.  
  23. DataTypeAttribute
  24. // Add type information.
  25. [DataType(DataType.EmailAddress)]
  26. public object EmailAddress;
  27.  
  28. RegularExpressionAttribute
  29. // Allow up to 40 uppercase and lowercase
  30. // characters. Use custom error.
  31. [RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$",
  32. ErrorMessage = "Characters are not allowed.")]
  33. public object FirstName;
  34.  
  35. // Allow up to 40 uppercase and lowercase
  36. // characters. Use standard error.
  37. [RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$")]
  38. public object LastName;
  39. }
  1. DisplayFormatAttribute
  2. public class ProductMetaData
  3. {
  4.  
  5. // Applying DisplayFormatAttribute
  6. // Display the text [Null] when the data field is empty.
  7. // Also, convert empty string to null for storing.
  8. [DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[Null]")]
  9. public object Size;
  10.  
  11. // Display currency data field in the format $1,345.50.
  12. [DisplayFormat(DataFormatString="{0:C}")]
  13. public object StandardCost;
  14.  
  15. // Display date data field in the short format 11/12/08.
  16. // Also, apply format in edit mode.
  17. [DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:d}")]
  18. public object SellStartDate;
  19. }
  1. DisplayColumnAttribute
  2. [DisplayColumn("City", "PostalCode", false)]
  3. public partial class Address
  4. {
  5. }
  6.  
  7. [DisplayColumn("LastName")]
  8. public partial class Customer
  9. {
  10. }
  1. EnumDataTypeAttribute
  2. public enum ReorderLevel
  3. {
  4. Zero = 0,
  5. Five = 5,
  6. Ten = 10,
  7. Fifteen = 15,
  8. Twenty = 20,
  9. TwentyFive = 25,
  10. Thirty = 30
  11. }
  12.  
  13. [MetadataType(typeof(ProductMD))]
  14. public partial class Product
  15. {
  16. public class ProductMD
  17. {
  18. [EnumDataType(typeof(ReorderLevel))]
  19. public object ReorderLevel { get; set; }
  20. }
  21. }
  1. StringLengthAttribute
  2. [MetadataType(typeof(ProductMetadata))]
  3. public partial class Product
  4. {
  5.  
  6. }
  7.  
  8. public class ProductMetadata
  9. {
  10.  
  11. [ScaffoldColumn(true)]
  12. [StringLength(4, ErrorMessage = "The ThumbnailPhotoFileName value cannot exceed 4 characters. ")]
  13. public object ThumbnailPhotoFileName;
  14.  
  15. [ScaffoldColumn(true)]
  16. [StringLength(4, ErrorMessage = "The {0} value cannot exceed {1} characters. ")]
  17. public object PhotoFileName;
  18.  
  19. }

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. pypeeter 自动化

    Pypputeer Puppeteer 是 Google 基于 Node.js 开发的一个工具,而 Pyppeteer 又是什么呢?它实际上是 Puppeteer 的 Python 版本的实现,但它不 ...

  2. i18n多语言 解决页面一刷新就恢复默认语言问题

  3. 发布 Net8预览版1(Announcing .NET 8 Preview 1)

    发布 net8预览版1(Announcing .NET 8 Preview 1) 1.对Net持续看好,对未来更加充满信心. 2.我主要关注Asp.Net Core .NET 8 中的新增功能 Wha ...

  4. 在端点0由GET_REPORT类请求上传报表

    目录 一般来说HID设备的报表在端点数量资源充裕的情况下都走中断端点上传,不会走控制端点即端点0上传,如果资源不足,可以利用端点0上传报表,USB协议中也是支持在端点0上传报表的. 以CH582为例, ...

  5. 打开Access时电脑出现蓝屏,错误编号0x00000116的问题解决

    Windows7 64位旗舰版,在打开Access 2013,Onenote 2013时均会出现蓝屏,现就出现蓝屏问题解决方法给大家做一个分享. 步骤: 1.右击我的电脑,打开设备管理器 2.按顺序1 ...

  6. [记] OpenCV4 源码编译安装 | 记录

    OpenCV4 源码编译安装 | 记录 参考资料 官方文档:https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html 环境 wsl2 ...

  7. redis-creating server tcp listening socket 127.0.0.1:6379: bind No error

    安装redis,出现如下错误: 解决方法: 步骤1:命令行下输入:redis-cli.exe(注意不是redis-server.exe) 然后输入:shutdown exit 退出后输入.\redis ...

  8. vue.cli的安装配置

    关于旧版本 Vue CLI 的包名称由 vue-cli 改成了 @vue/cli. 如果你已经全局安装了旧版本的 vue-cli(1.x 或 2.x),你需要先通过 npm uninstall vue ...

  9. IO基础知识与概念

    https://zhuanlan.zhihu.com/p/473639031

  10. 在 Vue 项目中使用 MQTT

    Vue 是一款由尤雨溪及其团队开发的渐进式 Javascript 前端框架.该框架具备数据双向绑定.组件化.响应式和轻量等特点,搭配其脚手架 Vue CLI 使得开发者更加容易上手,大大减少了学习成本 ...