I have a function, Name(int, DateTime)
, that I'd like to use in a linq2sql query.
Its a simple function that computes the difference between the passed in DateTime object and DateTime.Now using a TimeSpan
. I then do some basic math stuff with .TotalHours and the passed in int. The most complicated function is Math.Pow(double,double).
public static double Name(int num, DateTime Timestamp)
{
DateTime now = DateTime.Now;
DateTime then = Timestamp;
TimeSpan elapsedSpan = new TimeSpan(now.Ticks - posted.Ticks);
double t = elapsedSpan.TotalHours;
return System.Math.Pow(t, num);
}
I get this error:
Method 'Double Name(Int32, System.DateTime)' has no supported translation to SQL.
When running a query like this:
var q = from k in db.Stuff
select new {Name=Name(k.num, k.Timestamp)};
I understand that the function cannot be converted to SQL as it currently is written. Is there a way to convert what I have into something that is SQL useable?
I should note that a ToList() or ToArray() method is not useable because the datatable is large.