Deep Dive into LINQ Eran Sharabi.NET Development Team Leader JohnBryce Training

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

Źródło:
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Preface Demo A Quick Thank You How Did We Do It?
Feature: Identity Management - Login © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Taylor Brown Test Lead Microsoft Corporation ES09.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Windows 7 Training. Windows ® 7 Compatibility Session 0 Isolation Isolation of Windows 7 Services.
Feature: Microsoft Dynamics GP 2013 R2 Dashboards © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Reprint Outstanding Transactions Report © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Purchase Requisitions - Requester © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Co- location Mass Market Managed Hosting ISV Hosting.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
Multitenant Model Request/Response General Model.
Feature: Purchase Order Prepayments II © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Announcing Demo Announcing.
Feature: OLE Notes Migration Utility
Feature: Web Client Keyboard Shortcuts © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: SmartList Usability Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
 Rico Mariani Architect Microsoft Corporation.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Print Remaining Documents © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Connect with life Connect with life
Windows Azure Connect Name Title Microsoft Corporation.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Document Attachment –Replace OLE Notes © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Suggested Item Enhancements – Sales Script and Additional Information © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: Employee Self Service Timecard Entry © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
SQL Server SQL Azure Visual Studio“Quadrant” SQL Server Modeling Services Entity Framework ADO.NET“M”/EDM Data Services …
Ian Ellison-Taylor General Manager Microsoft Corporation PC27.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
demo Instance AInstance B Read “7” Write “8”

customer.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Feature: Suggested Item Enhancements – Analysis and Assignment © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and.
Windows Azure SQL Data Sync Name Title Microsoft Corporation.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
The CLR CoreCLRCoreCLR © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Joel Pobar Language Geek Microsoft DEV320 Improve on C# % Backwards Compatible Language Integrated Query (LINQ)
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Language Integrated Query Mike Taulty Developer & Platform Group Microsoft Ltd

IoCompleteRequest (Irp);... p = NULL; …f(p);
Ctrl-K, X Ctrl-K, S
Возможности Excel 2010, о которых следует знать
Title of Presentation 11/22/2018 3:34 PM
Title of Presentation 12/2/2018 3:48 PM
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
4/27/17, Bell #8 What amount of net pay has been earned this period?
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
Title of Presentation 7/24/2019 8:53 PM
Presentation transcript:

Deep Dive into LINQ Eran Sharabi.NET Development Team Leader JohnBryce Training

Objectives Using LINQ in more productivity Improve LINQ performance

Agenda Building LINQ from C# 2.0 Deferred vs. Non-Deferred Execution Enumerable vs. Queryable Types of LINQ and Tools Q & A Summary Tips and Best Practices

Building LINQ from C# 2.0 Generics and Iterators in C# 2.0 Lambda expressions Extension methods System.LINQ LINQ operators

DEMO Building LINQ from C# 2.0

DEMO Deferred vs. Non-Deferred Execution

var bad = from e in GetEmployees() from p in GetProjects() where e.GetDepartment() == p.GetDepartment() select new { Employee = e, Project = p }; Tips and Best Practices var good = from e in GetEmployees() let d = e.GetDepartment() from p in projects where d == p.Department select new { Employee = e, Project = p.Project }; var projects = (from p in GetProjects() select new { Project = p, Department = p.GetDepartment() }).ToArray(); join

Tips and Best Practices System.Collections.ArrayList arrayList; arrayList.Add(1); arrayList.Add("string"); // Ew, where's the generics? List integers = list.OfType ().ToList(); List strings = list.OfType ().ToList(); System.Collections.ArrayList arrayList; arrayList.Add(1); arrayList.Add("string"); // Ew, where's the generics? List integers = list.OfType ().ToList(); List strings = list.OfType ().ToList();

Tips and Best Practices System.Collections.ArrayList arrayList; arrayList.Add(1); arrayList.Add(2); // But they’re all integers! List list = list.Cast ().ToList(); System.Collections.ArrayList arrayList; arrayList.Add(1); arrayList.Add(2); // But they’re all integers! List list = list.Cast ().ToList();

Tips and Best Practices Aggregate – Sum, Min, Max, Average, … Set Operators – Union, Intersect, Except, SelectMany, SequenceEqual… More us/vcsharp/aa aspx Extension Methods

DEMO Tips and Best Practices

Expression Tree In-memory tree representation of LINQ Query Any LINQ Query node has it’s own type XXXExpression classes ExpressionType Enum Interpreted to specific data source by specific IQueryProvider like SQLQueryProvider

Expression Tree

DEMO

Enumerable vs. Queryable Both are static classes Both contains extension methods Enumerable extends IEnumarable Queryable extends IQueryable

Enumerable vs. Queryable Enumarable – Func<> delegate as method parameter – Intended for in-memory sequences iteration – Invokes the delegate as-is public static IEnumerable Select ( this IEnumerable source, Func selector ); public static IEnumerable Select ( this IEnumerable source, Func selector );

Enumerable vs. Queryable Queryable – Expression tree as method parameter – Expression tree Interpreted to specific data source by IQueryProvider – There is no “real” delegate public static IQueryable Select ( this IQueryable source, Expression > selector ); public static IQueryable Select ( this IQueryable source, Expression > selector );

Enumerable vs. Queryable Queryable C# 3.0 Compiler C# 3.0 Query IQueryProvider T-SQL Statements

DEMO Enumerable vs. Queryable

Compiled Query Specific data source cached query (Like T- SQL) Saved in the application memory for reuse Use CompiledQuery.Compile(…)

DEMO Compiled Query

LINQ Tools Expression Tree Debugger Visualizer SqlServer Query Debugger Visualizer Paste XML as LINQ Add-In Dynamic LINQ library LINQPad VLINQ – Visual LINQ Query Builder Linqer – SQL to LINQ Converter

DEMO LINQ Tools

NIH Is Bad! LINQ to XSD LINQ to Active Directory LINQ to WMI LINQ to Google / Ebay / Amazon… More: /10/09/the-linq-list-projects.aspx

Tips and Best Practices Open the connection once for multiple DB queries dbContext.Connection.Open(); //queries … dbContext.Connection.Close(); dbContext.Connection.Open(); //queries … dbContext.Connection.Close();

DEMO Types of LINQ

Q & A

Summary Using LINQ in more productivity Improve LINQ performance

Additional Resources Types of LINQ 008/10/09/the-linq-list-projects.aspx 008/10/09/the-linq-list-projects.aspx 101 LINQ samples us/vcsharp/aa aspx us/vcsharp/aa aspx

Related Sessions Hardcore C#: Hidden Power and Flexibility פבל יוסיפוביץ ' 09:00-10:30 Galil Hall Dynamic Languages and the.Net Framework שי פרידמן 14:30-15:40 Tavor Hall

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.