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.

references :
datediff avg

isnull try convert type of second expression first expression.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -