c# - LINQ to SQL running direct SQL for a scalar value -
i trying execute following raw sql linq has no proper support datediff
:
var str = @"select isnull(avg(datediff(day, addeddate, presentdate)), 0) days dummytable";
using linq sql, i'm trying output of above statement using:
var numberofdays = math.round(db.executequery<double>(str).firstordefault());
this give me error: specified cast not valid.
what doing wrong?
thanks in advance!
your code must change to:
var numberofdays = db.executequery<int>(str).firstordefault());
you think why? tell you:
return type of datediff in int.so return type of avg int. return type of isnull int too.
isnull try convert type of second expression first expression.
Comments
Post a Comment