我有这样的SQL,它从统计表中选择,分组和订购Url字段。 getDomain
是存储函数。我试图将这个SQL重写为Linq而没有任何运气。请有人解释一下如何做到这一点?
SELECT dbo.getDomain(Url) as url
FROM Statistic
GROUP BY dbo.getDomain(Url)
HAVING COUNT(Url) > 1
ORDER BY COUNT(Url)
答案 0 :(得分:3)
首先,您必须define your UDF in the .DBML
file包含其他表和过程定义。然后你可以在你的LINQ查询中Call any UDF function inline像这样:
var results = from s in dbo.Statistic
groub s by dbo.getDomain(s.url) into g
where g.Count() > 1
orderby g.Count() ascending
select new
{
URL = dbo.getDomain(g.Key)
};