{"id":418,"date":"2008-01-29T11:18:04","date_gmt":"2008-01-29T10:18:04","guid":{"rendered":"http:\/\/soci.hu\/blog\/index.php\/2008\/01\/29\/linq-hatekony-szures\/"},"modified":"2008-01-29T11:22:27","modified_gmt":"2008-01-29T10:22:27","slug":"linq-hatekony-szures","status":"publish","type":"post","link":"https:\/\/soci.hu\/blog\/index.php\/2008\/01\/29\/linq-hatekony-szures\/","title":{"rendered":"LINQ hat\u00e9kony sz\u0171r\u00e9s"},"content":{"rendered":"<p>Mi van, ha egy LINQ kifejez\u00e9sben olyan sz\u0171r\u00e9st szeretn\u00e9nk v\u00e9grehajtani, amit a LINQ2SQL r\u00e9teg nem tud okosan v\u00e9grehajtani, mert pl. TSQL f\u00fcggv\u00e9nyt kellene haszn\u00e1lnunk a where felt\u00e9telben?<br \/>\nHa nem \u00fcgyesked\u00fcnk, \u00e1tj\u00f6n a 100 milli\u00f3 sor az adatel\u00e9r\u0151 r\u00e9tegbe, azt\u00e1n sz\u0171r a LINQ maga. Sz\u00e9p is lenne.<\/p>\n<p>No, az <a href=\"http:\/\/blog.benhall.me.uk\/2008\/01\/datepartweek-with-linq-to-sql.html\">okoss\u00e1g<\/a> az ilyen esetekre az, hogy lehet haszn\u00e1lni TSQL f\u00fcggv\u00e9nyeket a LINQ where felt\u00e9telben. Ett\u0151l m\u00e9g nem lesz index seek, de legal\u00e1bb a szerver sz\u0171r.<\/p>\n<p>A linkelt p\u00e9ld\u00e1t kipr\u00f3b\u00e1ltam, t\u00e9nyleg a szerver sz\u0171r.<\/p>\n<p>AdwentureWorks-szel:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nAWDataContext dc = new AWDataContext();\r\ndc.Log = Console.Out;\r\n\r\nvar q = from o in dc.PurchaseOrderHeaders\r\n        where dc.WeekOfYear(o.OrderDate) == 23\r\n        select o;\r\n\r\nforeach (var item in q)\r\n{\r\n    Console.WriteLine(item.OrderDate);\r\n}\r\n<\/pre>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nALTER FUNCTION WeekOfYear(@Date DateTime)\r\nRETURNS Int\r\nAS\r\nBEGIN\r\nRETURN (CAST(DATEPART(ww, @Date) AS INT))\r\nEND\r\n<\/pre>\n<p>Az SQL, ami bemegy a szerverhez:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT &#x5B;t0].&#x5B;PurchaseOrderID], &#x5B;t0].&#x5B;RevisionNumber], &#x5B;t0].&#x5B;Status], \r\n&#x5B;t0].&#x5B;EmployeeID], &#x5B;t0].&#x5B;VendorID], &#x5B;t0].&#x5B;ShipMethodID], &#x5B;t0].&#x5B;OrderDate], \r\n&#x5B;t0].&#x5B;ShipDate],\r\n &#x5B;t0].&#x5B;SubTotal], &#x5B;t0].&#x5B;TaxAmt], &#x5B;t0].&#x5B;Freight], &#x5B;t0].&#x5B;TotalDue], \r\n&#x5B;t0].&#x5B;ModifiedDate]\r\nFROM &#x5B;Purchasing].&#x5B;PurchaseOrderHeader] AS &#x5B;t0]\r\nWHERE &#x5B;dbo].&#x5B;WeekOfYear](&#x5B;t0].&#x5B;OrderDate]) = @p0\r\n-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) &#x5B;23]\r\n-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.21022.8\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Mi van, ha egy LINQ kifejez\u00e9sben olyan sz\u0171r\u00e9st szeretn\u00e9nk v\u00e9grehajtani, amit a LINQ2SQL r\u00e9teg nem tud okosan v\u00e9grehajtani, mert pl. TSQL f\u00fcggv\u00e9nyt&#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,53,4,30,21,58],"tags":[],"class_list":["post-418","post","type-post","status-publish","format-standard","hentry","category-net","category-c","category-adatbazisok","category-linq","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\/418","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=418"}],"version-history":[{"count":0,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/418\/revisions"}],"wp:attachment":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}