Navigation: CodeStencil > Menus > Tools > Schema Generator > Data Annotations (5 of 6) |
Column Name: This will generate an annotation that looks similar to this:
[Column("Name")]
Order: If you entered a number in the "Order" field, you will an annotation similar to this is generated:
[Column("Name", Order = 1)]
Data Type: You can specify the data type of the column based on an enumeration of data types. This is list of the data types:
CreditCard - Represents a credit card number. Currency - Represents a currency value. Custom - Represents a custom data type. Date - Represents a date value. DateTime - Represents an instant in time, expressed as a date and time of day. Duration - Represents a continuous time during which an object exists. EmailAddress - Represents an email address. Html - Represents an HTML file. ImageUrl - Represents a URL to an image. MultilineText - Represents multi-line text. Password - Represent a password value. PhoneNumber - Represents a phone number value. PostalCode - Represents a postal code. Text - Represents text that is displayed. Time - Represents a time value. Upload - Represents file upload data type. Url - Represents a URL value.
Selecting EmailAddress will generate an annotation similar to this:
[DataType(DataType.EmailAddress)] public object EmailAddress;
Not Mapped: The NotMapped attribute can be applied to properties of an entity class for which we do not want to create corresponding columns in the database.
[NotMapped]
|
Required: This will generate an annotation similar to this:
[Required]
|
[MaxLength(50, ErrorMessage = "The {0} can not have more than {1} characters")] public string Name { get; set; }
|
[StringLength(maximumLength: 50 , MinimumLength = 10, ErrorMessage = "The property {0} should have {1} maximum characters and {2} minimum characters")] public string Name { get; set; }
|
This will generate an annotation like this:
public class Customer { public string Name { get; set; } public DateTime EntryDate { get; set; } public string Password { get; set; } [Compare("Customer.Password", ErrorMessage = "The fields Password and PasswordConfirmation should be the same")] public string PasswordConfirmation { get; set; } }
|
This will generate an annotation similar to this:
When "Primary Key" is checked: [Key]
When "Foreign Key Name" is not blank: [ForeignKey("StandardRefId")]
|
This will generate data annotation that will allow an index on a specific column.
[Index( "INDEX_CODE", IsClustered=true, IsUnique=true )]
|
This will generate an annotation similar to this:
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
This will generate an annotation similar to this:
[Range(10, 1000, ErrorMessage = "Value for {0} must be between {1} and {2}.")] public object Weight;
|
This will generate an annotation similar to this:
// 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;
|