{"id":448,"date":"2008-02-11T23:13:11","date_gmt":"2008-02-11T22:13:11","guid":{"rendered":"http:\/\/soci.hu\/blog\/index.php\/2008\/02\/11\/linq-vs-sql\/"},"modified":"2008-02-11T23:13:11","modified_gmt":"2008-02-11T22:13:11","slug":"linq-vs-sql","status":"publish","type":"post","link":"https:\/\/soci.hu\/blog\/index.php\/2008\/02\/11\/linq-vs-sql\/","title":{"rendered":"LINQ vs. SQL"},"content":{"rendered":"<p>Melyik a szimpatikusabb?<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nselect bucid, score, countMatchedEcid, ROW_NUMBER() \r\nOVER(ORDER BY score DESC) AS &#039;rank&#039; \r\nfrom (\r\nselect \r\nb.ucid as bucid,\r\na.ucid as aucid, \r\nsum(w.weight) as score,    \r\ncount(*) as countMatchedEcid\r\nfrom EcidNameValueSummary a, \r\ngenecidparts b, \r\nweights w \r\nwhere a.id=b.id \r\nand a.value=b.value \r\nand a.ucid!=b.ucid \r\nand w.id=a.id \r\nand w.allowed=1 \r\nand w.limit&gt;=a.countEcids \r\nand a.ucid=@ucid \r\ngroup by b.ucid, a.ucid\r\n) as hits\r\n<\/pre>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nvar matchQuery = from t in\r\n    (from a in c.EcidNameValueSummaries\r\n    join b in c.genecidparts\r\n    on a.id equals b.id\r\n    join w in c.Weights\r\n    on a.id equals w.id\r\n    where w.allowed == 1\r\n    &amp;&amp; w.limit &gt;= a.countEcids\r\n    &amp;&amp; a.value == b.value\r\n    &amp;&amp; a.ucid != b.ucid\r\n    &amp;&amp; a.ucid == ucid\r\n    select new\r\n    {\r\n        bucid = b.ucid,\r\n        aucid = a.ucid,\r\n        score = w.weight1\r\n    })\r\ngroup t by t.bucid into g\r\norderby g.Sum(e =&gt; e.score) descending\r\nselect new RankEntity\r\n{\r\n    Ucid = g.Key,\r\n    Score = g.Sum(e =&gt; e.score) ?? 0,\r\n    CountMatched = g.Count(),\r\n    Rank = 0\r\n};\r\n\r\n\r\nBindingListCollection&lt;RankEntity&gt; ranks = \r\nnew BindingListCollection&lt;RankEntity&gt;();\r\nint i = 1;\r\n\/\/It would be cool to do this with linq, but...\r\nforeach (RankEntity e in matchQuery)\r\n{\r\n    e.Rank = i++;\r\n    ranks.Add(e);\r\n}\r\nreturn ranks;\r\n<\/pre>\n<p>\u00c9s emellett, a ROW_NUMBER-t \u00e1t tudn\u00e1 nekem valaki ford\u00edtani LINQ-ra?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Melyik a szimpatikusabb? select bucid, score, countMatchedEcid, ROW_NUMBER() OVER(ORDER BY score DESC) AS &#039;rank&#039; from ( select b.ucid as bucid, a.ucid as&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,25,10,6,53,4,30,21],"tags":[],"class_list":["post-448","post","type-post","status-publish","format-standard","hentry","category-net","category-adonet","category-c","category-adatbazisok","category-linq","category-szakmai-elet","category-sql-server","category-sql-server-2005"],"_links":{"self":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=448"}],"version-history":[{"count":0,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/448\/revisions"}],"wp:attachment":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}