简体   繁体   English

C#实体框架-十进制错误

[英]C# Entity FrameWork - Decimal error

Trying to execute this code: 尝试执行以下代码:

process.POPManagerPreparation.JudgementPercentage = (decimal?)txtAlternativePercentage.Value;

That works fine, but when the code Context.Current.SaveChanges(); 那很好,但是当代码Context.Current.SaveChanges(); is executed to save it in the database this ArgumentException occurs: 被执行以将其保存在数据库中,发生此ArgumentException:

An error occurred while updating the entries. See the inner exception for details.
System.ArgumentException: Parameter value '3,0000' is out of range.

It's definitely about the field i've added, I know because of the value. 因为价值,我绝对知道这是我添加的领域。 (it changes when I check with other input) (在和其他的输入确认的时候改变)

I tried to change my computer settings from NL-nl to US-en, because it feels like there is something wrong with that but didn't solve it, the same error still exist. 我试图将计算机设置从NL-nl更改为US-en,因为感觉这有问题,但没有解决,仍然存在相同的错误。

Also tried some things on the text field, same error still: 在文本字段上也尝试了一些操作,仍然出现相同的错误:

    <telerik:RadNumericTextBox MinValue="0" MaxLength="100" ID="txtAlternativePercentage"
     runat="server" Type="Percent" Culture="en-US" Width="80px" LabelCssClass=""
     Label="Verhogingspercentage:" LabelWidth="130" AutoPostBack="true"
     OnTextChanged="SalaryChanged" Visible="false">
             <NumberFormat DecimalDigits="1" />
             <IncrementSettings InterceptArrowKeys="False" InterceptMouseWheel="False" />
    </telerik:RadNumericTextBox>

To be complete, the database field is: decimal(10, 5) so that's seems to be alright too. 为了完整起见,数据库字段是: decimal(10, 5)所以看起来也不错。 Found online a lot of issues with people that used too small fields but nothing on my issue. 在网上发现了很多问题,这些人使用的字段太小,但我的问题一无所获。

You can specify the precision of your properties in your modelBuilder: 您可以在modelBuilder中指定属性的精度:

modelBuilder.Entity<POPManagerPreparation>()
            .Property(e => e.JudgementPercentage)
            .HasPrecision(10,5);

I solved it by changing to a float field like Pankaj Gupta suggested. 我通过改成Pankaj Gupta建议的浮点字段来解决它。 This works fine. 这很好。

so I've learned to not use a decimal unless you are sure that the value is strict about the decimal form it expects. 因此,我已经学会了不要使用小数,除非您确定该值对于期望的小数形式严格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM