asp.net mvc common data annotations and validation and an example of Entity Framework data mapping __.net

Source: Internet
Author: User

Below is the Administrator information table for the model layer

In this model we used asp.net MVC data annotation and verification, can be used as backend verification, Entity Framework to the database mapping

   Using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.ComponentModel.DataAnnotations.Schema;
 6 using System.ComponentModel.DataAnnotations;
 7 using SYSTEM.WEB.MVC;
 8 using System.ComponentModel;
9 namespace Snsmodel [Table ("Admininfo")] [public partial class Admininfo [Key] [Display (Name = "number:")] [Column ("Id")] is public int Id {get; Set [Required (errormessage = "* Cannot be empty!")] [RegularExpression (@] ^[\u4e00-\u9fa5\uf900-\ufa2d\w\.\s]{6 , 18}$ ", errormessage =" *6-18 digit pinyin or number ")] [Column (TypeName =" nvarchar ")] [MaxLength ()] [D Isplay (name = "Username:")]///[remote ("Checkusername", "account")] is public string UserName {get; set;} 2 7 [Required (errormessage = "* Cannot be empty!")] [RegularExpression (@ "^[\u4e00-\u9fa5\uf900-\ufa2d\w\.\s]{6,18 }$ ", errormessage =" *6-18 digit pinyin or digit ")] [TypeName = "nvarchar")] [MaxLength] [MinLength (6)] [Display (Nam E = "Password:")] [DataType (Datatype.password)] is public string Password {get; Set         (TypeName = "nvarchar")] [Display (name = "real name:")] [MaxLength (20)] 40 public string Truename {get; set;} [Display (Name = "is available:")]? isuseful {get; set;} [ReadOnly (True)] [Display (Name = "creation Time:")] is public DateTime Cre attime {get; set;} [Display (Name = "Rank")] is a public int? Orders {get; set;} [notmapped] [Required (errormessage = "* Cannot be empty!")] [Regularexpressi         On (@ "^[\u4e00-\u9fa5\uf900-\ufa2d\w\.\s]{6,18}$", errormessage = "*6-18 bit pinyin or number")] [Display (Name = "New password")] 56       [DataType (Datatype.password)] is public virtual string PassWord1 {get; set;} 58 59  [Notmapped] [Compare ("PassWord1", errormessage = "New password and Confirm password inconsistent!")] [Required (errormessage =] * cannot be empty!         ] [RegularExpression (@ "^[\u4e00-\u9fa5\uf900-\ufa2d\w\.\s]{6,18}$", errormessage = "*6-18 bit pinyin or number")] 63 [Display (Name = Confirm password)] [DataType (Datatype.password)] is a public virtual string PassWord2 {get; set; } 66} 67}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.