How to get rid of 'property could not be set to a double value, you must set this property to a non-null value of type decimal'

安稳与你 提交于 2019-12-07 16:00:43

问题


I'm trying to get a function import to work correctly. EF calls out to my stored procedure, but the result has an inner exception that I don't understand:

var result = context.SomeFunctionImport();

I get:

The 'Cnt' property on 'SomeClass' could not be set to a 'Double' value. You must set this property to a non-null value of type 'Decimal'.

Here's the Cnt property on SomeClass:

    [DataMember]
    public Nullable<decimal> Cnt
    {
        get { return _cnt; }
        set
        {
            if (_cnt != value)
            {
                OnComplexPropertyChanging();
                _cnt = value;
                OnPropertyChanged("Cnt");
            }
        }
    }
    private Nullable<decimal> _cnt;

回答1:


You need to define it like this: public decimal Cnt




回答2:


Found the issue. My stored procedure was missing a cast on Cnt after a rounding operation.




回答3:


I think this field is float type in your database table. so you need to set it double? if this field is nullable or otherwise use double

public double? field_name {get; set}
// or 
public double field_name {get; set}

It's working for me




回答4:


I had this problem and my issue was that on the DB, the type was real and in the EF class was declared as decimal. I just changed the DB type to real and problem solved.



来源:https://stackoverflow.com/questions/6851696/how-to-get-rid-of-property-could-not-be-set-to-a-double-value-you-must-set-thi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!