samedi 9 janvier 2016

UWP - Data Annotations

Model:

class BlaBla
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    [Required(ErrorMessage = "The {0} field is required.")]
    [StringLength(100, MinimumLength = 2, ErrorMessage = "Value for {0} must be between {2} and {1}.")]
    [RegularExpression(@"^([a-zA-Z\u00c0-\u01ff]([\s]?))+$", ErrorMessage = "The field {0} is not in the correct format.")]
    public string Name { get; set; }

    [Required(ErrorMessage = "The {0} field is required.")]
    [RegularExpression(@"^\d{1,2}.\d$", ErrorMessage = "The field {0} is not in the correct format.")]
    public float Meterage { get; set; }

    [Display(Name = "Date of Birth")]
    [DataType(DataType.DateTime)]
    [Required(ErrorMessage = "The {0} field is required.")]
    public DateTime Date { get; set; }
}

I ran the code and it's fine. The table BlaBla was created on SQLite (look below) without problems, but without any constraints, why? What am I doing wrong?

The code that was generated in SQLite:

CREATE TABLE "BlaBla"(
"Id" integer primary key autoincrement not null ,
"Name" varchar ,
"Meterage" float ,
"Date" datetime );

CREATE UNIQUE INDEX "BlaBla_Id" on "BlaBla"("Id");

I suppose it must set everything to "NOT NULL" and with the maximum number of characters.

Aucun commentaire:

Enregistrer un commentaire