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;
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
你需要像这样定义: public decimal Cnt
Found the issue. My stored procedure was missing a cast on Cnt after a rounding operation.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.