c# – Linq-To-SQL中的黑客新闻样式排序算法

根据this site,黑客新闻的排序算法是这样的:
(p – 1) / (t + 2)^1.5
Description:
Votes divided by age factor
p = votes (points) from users. t =
time since submission in hours.p is subtracted by 1 to negate
submitters vote. age factor is (time
since submission in hours plus two) to
the power of 1.5.
给定一个与此类似的表结构:
Item
ID
Link
DatePostedItem_Votes
ItemID
Value
使用linq to sql实现算法的最佳方法是什么,我能够完全在linq中编写查询,还是需要使用存储过程或其他东西.
更新.根据TJB的答案结束使用下面的代码:
var votesQuery =
from i in db.Items
join v in db.Item_Votes on i.ItemID equals v.ItemID
orderby
(double)(v.Value - 1) /
Math.Pow(
(DateTime.Now - i.DatePosted.Value).TotalHours + 2,
1.5) descending
select i;
解决方法:
使用2 1 Linq查询(可能还有更有效的方法)
var votesQuery =
from i in items
join v in votes on i.Id equals v.ItemId
orderby
(v.Value - 1) /
Math.Pow(
(DateTime.Now - i.Posted).Add(new TimeSpan(2,0,0)).Hours,
1.5 )
select new
{
Item = i,
Vote = v
};