Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert function to LINQ to SQL

I have such SQL which select, group and order Url field from Statistic table. getDomain is stored function. I am trying to rewrite this SQL to Linq without any luck. Please someone explain how to do that?

SELECT  dbo.getDomain(Url) as url
FROM Statistic
GROUP BY dbo.getDomain(Url)
HAVING COUNT(Url) > 1
ORDER BY COUNT(Url)
like image 968
Tomas Avatar asked Feb 16 '26 01:02

Tomas


1 Answers

First you have to define your UDF in the .DBML file that contains other tables and procedures definitions. Then you can Call any UDF function inline within your LINQ query Like this:

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)
              };
like image 118
Mahmoud Gamal Avatar answered Feb 17 '26 15:02

Mahmoud Gamal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!