0

コードで範囲 (または他のモデルDataAnnotations属性) を設定し、すべてのDataAnnotations動作を維持することは可能ですか?

つまり、ValidationMessageFor?

私の現在の「静的」モデル

[Required]
[DisplayName("Price")]
[RegularExpression(@"[0-9]+(\.[0-9][0-9]?)?$", ErrorMessage = "Invalid price format")]
public decimal MinimumPrice { get; set; }

ありがとう!

4

2 に答える 2

0

Fluent API を使用して、必要なことのいくつかを実現できます。

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<SomeClass>()
        .Property(x => x.MinimumPrice )
            .IsRequired()
            .HasColumnType("decimal")
            .HasPrecision(18, 2);     
            // default vals for decimal type. 18 = precision = how many digits in 
            // total. 2 = scale = digits after decimal                   
}

流暢な構成を使用した方が良い場合もあれば、注釈を使用した方が良い場合もあります。

さらに読む

于 2013-05-16T23:18:41.187 に答える