型号:
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; }
}我运行了代码,一切正常。表BlaBla是在SQLite上创建的(如下所示),没有问题,但是没有任何约束,为什么?我做错了什么?
在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");我认为它必须将所有内容都设置为“非空”,并设置最大字符数。
发布于 2016-01-11 17:09:42
据我所知,SQLite.NET包装器没有任何“必需”属性,它的NotNull属性也没有任何Message属性。
如果你想在“插入”操作中显示错误消息,我认为你必须实现一些自定义的解决方案,或者使用另一个ORM/SQLite库。
您可以检查official GitHub repo以查看所有受支持的属性。
https://stackoverflow.com/questions/34701781
复制相似问题