Best Data annotation for a Decimal(18,2)

后端 未结 8 1303
無奈伤痛
無奈伤痛 2020-12-14 05:57

I have a column inside my sql server 2008 wih type of Decimal(18,2). But on entity framework what is the best data annotation validation I can apply to this pro

8条回答
  •  青春惊慌失措
    2020-12-14 06:44

    For a different approach which some may consider more readable, you can override the OnModelCreating method of your DbContext to set precision, like so:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
    
               modelBuilder.Entity()
                        .Property(x => x.TheProprty)
                        .HasPrecision(18, 2);
        }
    

    Advantage: strongly typed vs custom regular expression

    Disadvantage: can't see it on the class with just a scan

提交回复
热议问题