首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UWP -数据标注

UWP -数据标注
EN

Stack Overflow用户
提问于 2016-01-10 11:34:48
回答 1查看 838关注 0票数 0

型号:

代码语言:javascript
复制
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中生成的代码:

代码语言:javascript
复制
CREATE TABLE "BlaBla"(
"Id" integer primary key autoincrement not null ,
"Name" varchar ,
"Meterage" float ,
"Date" datetime );

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

我认为它必须将所有内容都设置为“非空”,并设置最大字符数。

EN

回答 1

Stack Overflow用户

发布于 2016-01-11 17:09:42

据我所知,SQLite.NET包装器没有任何“必需”属性,它的NotNull属性也没有任何Message属性。

如果你想在“插入”操作中显示错误消息,我认为你必须实现一些自定义的解决方案,或者使用另一个ORM/SQLite库。

您可以检查official GitHub repo以查看所有受支持的属性。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34701781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档