1. This is the class generated by EF:
namespacePMS. dataprovider.entityframework{usingSystem; usingSystem.Collections.Generic; Public Partial classM_managers { Public stringUserName {Get;Set; } Public stringNickname {Get;Set; } Public stringPassWord {Get;Set; } Public stringheadimg {Get;Set; } Public intAge {Get;Set; } Public BOOLIsmale {Get;Set; } Public stringEmail {Get;Set; } Public stringMobile {Get;Set; } Public stringAddress {Get;Set; } Public stringSignature {Get;Set; } Public stringRoles {Get;Set; } Public stringDescription {Get;Set; } PublicSystem.DateTime CreateDate {Get;Set; } Public stringCreateUser {Get;Set; } PublicSystem.DateTime Lastlogindate {Get;Set; } Public intLogintimes {Get;Set; } }}
2. Create a new part (partial) class:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel.DataAnnotations;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacePMS. dataprovider.entityframework{[Metadatatype (typeof(M_managersmetadata))] Public Partial classm_managers {} Public classM_managersmetadata {[Display (Name="User name")] [Required (ErrorMessage="*")] [Stringlength ( -, errormessage ="the character length should be between 6-50", Minimumlength =6)] Public stringUserName {Get;Set; } [Display (Name="Display Name")] [Required (ErrorMessage="*")] [Stringlength ( -, errormessage ="the character length should be between 6-50", Minimumlength =6)] Public stringNickname {Get;Set; } [Display (Name="Password")] [Required (ErrorMessage="*")] [DataType (Datatype.password)] [Stringlength ( -, errormessage ="the character length should be between 6-50", Minimumlength =6)] Public stringPassWord {Get;Set; } [Display (Name="Avatar")] [DataType (Datatype.imageurl)] Public stringheadimg {Get;Set; } [Display (Name="Age")] [Range (Ten, -, errormessage ="The age should be between 10-120")] Public intAge {Get;Set; } [Display (Name="Sex")] Public BOOLIsmale {Get;Set; } [Display (Name="Email")] [Required (ErrorMessage="*")] [DataType (datatype.emailaddress)] [EmailAddress (ErrorMessage="The mailbox format is not correct")] [Stringlength ( -, errormessage ="the character length should be between 6-50", Minimumlength =6)] Public stringEmail {Get;Set; } [Display (Name="Mobile Phone")] [Required (ErrorMessage="*")] Public stringMobile {Get;Set; } [Display (Name="Address")] Public stringAddress {Get;Set; } [Display (Name="Signature")] Public stringSignature {Get;Set; } [Display (Name="role")] Public stringRoles {Get;Set; } [Display (Name="Description")] [DataType (datatype.multilinetext)] Public stringDescription {Get;Set; } [Display (Name="Date Created")] [DataType (Datatype.datetime, ErrorMessage="date format is incorrect")] PublicSystem.DateTime CreateDate {Get;Set; } [Display (Name="Create Person")] Public stringCreateUser {Get;Set; } [Display (Name="Last Login Date")] [DataType (Datatype.date, ErrorMessage="date format is incorrect")] PublicSystem.DateTime Lastlogindate {Get;Set; } [Display (Name="Number of Logins")] Public intLogintimes {Get;Set; } }}
Attention:
[Metadatatype (typeof(M_managersmetadata))]//Specifies the metadata class to be associated for the newly created partial class Public Partial classM_managers//This is the new section class (Empty Inside, nothing written), and note that the class name and namespace are the same as those generated by EF { } Public classM_managersmetadata//Create a new metadata class { //Write model validation here[Display (Name ="User name")] [Required (ErrorMessage="*")] [Stringlength ( -, errormessage ="the character length should be between 6-50", Minimumlength =6)] Public stringUserName {Get;Set; } }
Entityframework-dbfirst-after re-generation of the Write verification disappears (workaround)