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'
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;
You need to define it like this: public decimal Cnt
Found the issue. My stored procedure was missing a cast on Cnt after a rounding operation.
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
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.
精彩评论