Mvc在小数上设置精度

时间:2017-11-10 06:39:55

标签: c# asp.net-mvc entity-framework

我正在计算一些薪水。我读过其他一些提到名为OnModelCreating(DbModelBuilder modelBuilder)的方法的帖子,但我无法找到它。并且很难弄清楚在哪里创造这个。

我有这个模型

public Decimal? Amount { get; set; }
 public Decimal? hours { get; set; }
 public Decimal? Total { get; set; }

其中总数按金额+(小时数*)计算,所以我需要预设量表至少为5位小数。

我的Init.cs

Berett = c.Decimal(precision: 18, scale: 2)

尝试实施ModelOnCreate

时出现此错误
    Project.Models.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
Project.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.

像这样添加:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Pay>().Property(e => e.Total).HasPrecision(18, 6);
    }

0 个答案:

没有答案