{"id":939,"date":"2009-10-12T09:16:17","date_gmt":"2009-10-12T08:16:17","guid":{"rendered":"http:\/\/soci.hu\/blog\/?p=939"},"modified":"2009-10-12T09:16:17","modified_gmt":"2009-10-12T08:16:17","slug":"random-orderby-linq-es-ef-hasznalataval","status":"publish","type":"post","link":"https:\/\/soci.hu\/blog\/index.php\/2009\/10\/12\/random-orderby-linq-es-ef-hasznalataval\/","title":{"rendered":"Random orderby Linq \u00e9s EF haszn\u00e1lat\u00e1val"},"content":{"rendered":"<p>Az SQL Serveren szok\u00e1sos orderby newid() szerveroldali megold\u00e1st csak linq to SQL eset\u00e9n tudjuk kihaszn\u00e1lni, <a href=\"http:\/\/linqinaction.net\/blogs\/main\/archive\/2008\/01\/10\/randomizing-linq-to-sql-queries.aspx\">szerveroldali f\u00fcggv\u00e9nnyel<\/a>. Az EF-ben az ilyesmi nem megy:<\/p>\n<p>&#8230; orderby Guid.NewID() &#8230;<\/p>\n<p>Ez az EF verzi\u00f3 m\u00e9g nem tudja leford\u00edtani szerveroldali kifejez\u00e9ss\u00e9 az orderby kifejez\u00e9s\u00e9t.<br \/>\nViszont a random rendez\u00e9st \u00e1t lehet nyomni kliensoldalra, ha a lek\u00e9rdez\u00e9st &#8220;materializ\u00e1luk&#8221; (AsEnumerable) el\u0151bb:<\/p>\n<p>Random rnd = new Random();<br \/>\n(from s in ATSEntities.Instance.Symbol<br \/>\nselect s).AsEnumerable().OrderBy(o => rnd.Next()));<\/p>\n<p>Nem guidot haszn\u00e1ltam, hanem Randomot, az kisebb k\u00f6lts\u00e9g\u0171, \u00e9s az \u00e9n c\u00e9lomra nem baj, ha csak pszeudo-random a sorrend.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Az SQL Serveren szok\u00e1sos orderby newid() szerveroldali megold\u00e1st csak linq to SQL eset\u00e9n tudjuk kihaszn\u00e1lni, szerveroldali f\u00fcggv\u00e9nnyel. Az EF-ben az ilyesmi nem&#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,10,6,4,30,21,58],"tags":[],"class_list":["post-939","post","type-post","status-publish","format-standard","hentry","category-net","category-c","category-adatbazisok","category-szakmai-elet","category-sql-server","category-sql-server-2005","category-sql-server-2008"],"_links":{"self":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/939","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=939"}],"version-history":[{"count":1,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/939\/revisions"}],"predecessor-version":[{"id":940,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/939\/revisions\/940"}],"wp:attachment":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}