1 / 13

Compiled Queries : LINQ-Abfragen mit Pegasus-Stiefeln

Compiled Queries : LINQ-Abfragen mit Pegasus-Stiefeln. Gordon Breuer IT Consultant & Software Engineer Travel & Logistics. Die Inhalte. Wo / Wie entsteht das Problem. Wo und wie entsteht der Performance-Engpass?. IEnumerable < Customer >  linq  =  from customer in db. Customer

rod
Download Presentation

Compiled Queries : LINQ-Abfragen mit Pegasus-Stiefeln

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CompiledQueries: LINQ-Abfragen mit Pegasus-Stiefeln Gordon Breuer IT Consultant & Software Engineer Travel & Logistics

  2. Die Inhalte

  3. Wo / Wie entsteht das Problem

  4. Wo und wie entsteht der Performance-Engpass? • IEnumerable<Customer> linq = fromcustomerindb.Customer • wherecustomer.LastName.StartsWith("B") • selectcustomer; IQueryable<Customer> lambda = db.Customer.Where(customer => customer.LastName.StartsWith("B")); Magic Expression<Func<Customer, bool>> bedingung = s => s.LastName.StartsWith("B"); IQueryable<Customer> lambda = db.Customer.Where(bedingung); SELECT * FROM Customer WHERE LastName = 'B%'

  5. Wo und wie entsteht der Performance-Engpass? • IEnumerable<Customer> linq = fromcustomerindb.Customer • wherecustomer.LastName.StartsWith("B") • selectcustomer; IQueryable<Customer> lambda = db.Customer.Where(customer => customer.LastName.StartsWith("B")); Expression<Func<Customer, bool>> bedingung = s => s.LastName.StartsWith("B"); IQueryable<Customer> lambda = db.Customer.Where(bedingung); SELECT * FROM Customer WHERE LastName = 'B%'

  6. CompiledQueries als Lösung

  7. CompiledQueries • Verfügbar seit .NET 3.5 • Namensraum System.Data.Linq • Statische Klasse CompiledQuery • Compile<TArg0, …, TResult>(Expression<Func<TArg0, …, TResult>>)

  8. CompiledQueries • 1. Parameter = Objekt-Kontext für den Datenzugriff • Letzter Parameter (n) = Rückgabewert • 2. - (n-1). Parameter = Optionale Übergabeparameter • In .NET 3.5 und Silverlight: Überladungen für bis zu drei Übergabeparameter • In .NET 4.0+: Überladungen für bis zu 15 Übergabeparameter • Sollten mehr gebraucht werden: Helferklasse

  9. Instanzen vs. Statische Klassen • Aufruf in instanziierten Klassen? • Statischer Kontext!

  10. Die Vor- und Nachteile im Überblick

  11. Tipps zur Verwendung • Alle CompiledQueries in einer eigenen statischen Klasse sammeln • Es muss immer der gleiche Data-Kontext verwendet werden • Das zurückgegebene one-time Enumerable in eine Liste umwandeln

  12. Demos in Visual Studio

  13. eure msgsystemsag Robert-Bürkle-Straße 1 85737 Ismaning/München Telefon: +49 89 96101-0 Fax: +49 89 96101-1113 info@msg-systems.com www.msg-systems.com Gordon Breuer IT Consultant // Software Engineer Telefon: +49 160 9091 5143 E-Mail: gordon.breuer@msg-systems.de Twitter: @anheledir Facebook: http://facebook.com/gordon.breuer Blog: http://gordon-breuer.de

More Related