Applied Linq Putting Linq to work Introducing… Class-A Kennisprovider Microsoft development Training Coaching Alex Thissen Trainer/coach.

Slides:



Advertisements
Similar presentations
The Microsoft Technical Roadshow 2007 Language Enhancements and LINQ Daniel Moth Developer & Platform Group Microsoft Ltd
Advertisements

Language Integrated Query (LINQ) Martin Parry Developer & Platform Group Microsoft Ltd
XML: Extensible Markup Language
Michael Pizzo Software Architect Data Programmability Microsoft Corporation.
© Logica All rights reserved ADO vNext LINQ LINQ to SQL Entity Framework Freek Leemhuis
Live from Redmond: WebCast Conquering XML with Visual Basic 9 Amanda Silver Lead Program Manager Visual Basic Level: Starts Easy, Finishes Advanced.
Damien Guard (BSc, MBCS) Guernsey Software Developer Forum Language Integrated Query:
UML – Class Diagrams.
.NET Framework V3.5+ & RESTful web services Mike Taulty Developer & Platform Group Microsoft Ltd
WCF RIA Services - Querying and Updating Data SILVERLIGHTSHOW.NET WEBINARS SERIES BRIAN NOYES, CHIEF ARCHITECT, IDESIGN INC 2 FEB 2011.
The Microsoft Technical Roadshow 2007 Advances for Data in VS “Orcas” Mike Taulty Developer & Platform Group Microsoft Ltd
© Copyright SELA Software & Education Labs Ltd Baruch Hirsch St. Bnei Brak Israel Microsoft Entity Framework v1.1 over Oracle Database Erez.
A tour of new features introducing LINQ. Agenda of LINQ Presentation We have features for every step of the way LINQ Fundamentals Anonymous Functions/Lambda.
Discover, Master, InfluenceSlide 1 SQL Server Compact Edition and the Entity Framework Rob Sanders Readify.
Beth Massi Program Manager Visual Studio Community.
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
LINQ Programming in C# LINQ CSE Prof. Roger Crawfis.
 Introduction  What is LINQ  Syntax  How to Query  Example Program.
LINQ, An IntroLINQ, An Intro Florin−Tudor Cristea, Microsoft Student Partner.
Eric Vogel Software Developer A.J. Boggs & Company.
Session 1 - Introduction and Data Access Layer
Entity Framework, a quickstart Florin−Tudor Cristea, Microsoft Student Partner.
Lesley Bross, August 29, 2010 ArcGIS 10 add-in glossary.
Using Visual Basic 6.0 to Create Web-Based Database Applications
Eric Nelson (or )
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
ADO.NET DATA SERVICES Mike Taulty Developer & Platform Group Microsoft UK
LINQ TO XML Mike Taulty Developer & Platform Group Microsoft UK
Introduction to LINQ Lecture # 19 August Introduction How do you interrogate/manipulate data? What if you could do the work in a type-safe," string-free.
Лектор: Борислава Палева. Galin Iliev MCT, MCPD, MCSD.NET LINQ to XML.
Ronnie Saurenmann Principal Architect Microsoft Switzerland.
LINQ: It’s Not Your Father’s Data Access Denny Boynton Anheuser-Busch Companies.
The.NET Language Integrated Query Project Anders Hejlsberg TLN306 Technical Fellow Microsoft Corporation.
ADO.NET Entity Framework Mike Taulty Developer & Platform Group Microsoft Ltd
 Language Integrated Query  Make query a part of the language  Component of.NET Framework 3.5  Shipped with Visual Studio 2008.
LINQ Providers Or why.NET rules, and Java doesn’t Branimir Giurov SofiaDev.org UG Lead, C# MVP Freelance Software Developer
Declaratively Producing Data Mash-ups Sudarshan Murthy 1, David Maier 2 1 Applied Research, Wipro Technologies 2 Department of Computer Science, Portland.
 Although VERY commonly used, arrays have limited capabilities  A List is similar to an array but provides additional functionality, such as dynamic.
Introduction to LINQ Chapter 11. Introduction Large amounts of data are often stored in a database—an organized collection of data. A database management.
Oct * Brad Tutterow. VS 2008.NET 3.5LINQ Entity Framework  The ADO.NET Entity Framework is part of Microsoft’s next generation of.NET technologies.
AUC Technologies LINQ (Language Integrated Query) LINQ Presented By : SHAIKH SHARYAR JAVED Software Engineer (Daedalus Software Inc.) Technology Teacher.
1 ADO.NET Data Services Mike Taulty Developer & Platform Group Microsoft Ltd
Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International.
Inside LINQ to Objects How LINQ to Objects work Inside LINQ1.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Linq Overview Vincent GERMAIN. Evolution - Rappel Langage  C# 2.0  C# 3.0 (Local type inference, Lambda expression, Method extension,Anonymous type)
Damien Guard (BSc, MBCS) Guernsey Software Developer Forum Language Integrated Query:
LINQ Language Integrated Query LINQ1. LINQ: Why and what? Problem Many data sources: Relational databases, XML, in-memory data structures, objects, etc.
Ken Casada Developer Evangelist Microsoft Switzerland
ADO.NET 3.0 – Entity Data Model Gert E.R. Drapers Chief Software Architect Visual Studio Team Edition for Database Professionals Microsoft Corporation.
Language Integrated Query Mike Taulty Developer & Platform Group Microsoft Ltd
Data Access Methodologies: When to choose what (ADO.NET, Entity Framework, WCF Data Services) Wriju Ghosh Lead Partner Consultant, Microsoft.
Introduction to.NET Florin Olariu “Alexandru Ioan Cuza”, University of Iai Department of Computer Science.
Introducing the Microsoft® .NET Framework
Introduction to Entity framework
Part 1: Overview of LINQ Intro to LINQ Presenter: PhuongNQK.
Introduction to Entity Framework
Jim Fawcett CSE681 – Software Modeling and Analysis Fall 2016
Jim Fawcett CSE681 – Software Modeling and Analysis Fall 2013
Language Integrated Query: (LINQ) An introduction
ADO.NET Entity Framework
Introduction to LINQ Chapter 11 10/28/2015 Lect 4 CT1411.
Language Integrated Query (LINQ)
Entity Framework Core.
Visual Studio “Orcas” & .NET Framework v3.5
Introduction to LINQ Chapter 11.
Visual Studio 2008 Mike Taulty Developer & Platform Group
LINQ - 2 Ravi Kumar C++/C# Team.
.NET Framework V3.5+ & RESTful web services
Presentation transcript:

Applied Linq Putting Linq to work

Introducing… Class-A Kennisprovider Microsoft development Training Coaching Alex Thissen Trainer/coach

Agenda About Linq and queries Query providers and APIs What it means to apply Linq –Language and code –Query execution –Recommendations –Architecture Beyond Linq Demos Questions and discussion

Dim query = From c In customers _ Where c.Orders.Count > 100 _ Order By c.CompanyName Descending _ Select c Introducing Linq Uniform way to write queries over data Linq is about query keywords –Built into new languages C# 3.0 and VB 9.0 Linq is about query operators –40+ standard query operators are defined –Methods that operate in queries or act on its results var query = from c in customers where c.Orders.Count > 100 orderby c.CompanyName descending select c;

About Linq queries Expressed in terms of CLR types –Objects that might or might not exist in-memory Linq queries are not SQL queries at all Compositional and hierarchical by nature –Arbitrary nesting of queries –Additional operators can be applied to query Declarative instead of imperative –Tell what you want, not how –How is up to underlying implementation

Writing queries Learn the keywords and operators –Not all operators have corresponding keywords or language integration –Number of keywords may vary per language Some parts must be written with operators –Usually exposes lambda expressions Queries can be done without keywords –Explicit dot notation (what compiler creates) –Sometimes FLWOS is overkill

var query = from c in customers select c.Orders.Sum(o => o.Amount); var query2 = (from c in customers select c.Country).Distinct(); Customer someCustomer = customers.FirstOrDefault(c => c.ID == 1337); Dim query = _ From c In customers _ Select c.Orders.Sum( _ Function (o As Order) o.Amount) _ ) Dim query2 = From c In customers _ Select c.Country _ Distinct Query samples * VB Lambda expressions will appear in Beta 2 *

Demos Getting familiar with Linq queries –Query operations: selection, projection, grouping –Using keywords and operators

Sources of data Your data must come from somewhere 1.In-memory CLR objects 2.Database 3.XML 4.Other repositories: registry, Active Directory, … Various flavors of Linq disclose certain type of data Query syntax does not change per source –Set of keywords and operators available might be different

Linq to XML Power of Linq brought to data in XML format 1.Perform queries over XML data 2.New element-centric API to manipulate XML Faster alternative to System.Xml DOM API 3.Functional construction of XML data with query expressions

Linq to SQL Generates object model to represent data Mapping of CLR types to database tables –Object/Relational Mapping (OR/M) technology –1:1 relationships between objects and tables –Translates Linq queries to SQL statements Builds on ADO.NET and.NET Transactions Persistence services –Automatic change tracking and identity management of objects –Updates by SQL statements or stored procedures

Mapping strategy Relationships map to collection properties Single table inheritance is supported Customer table CityNameID Data context Order table Custom erID OrderD ate ID Customer object Order objects

Two kinds of Linq Enumerable typesQueryable types ExecutionLocal in-memoryUsually remote ImplementationIterators using yield return Expression tree parsing Interface IEnumerable IQueryable ProvidersLinq to Objects Linq to SQL Entities (after 3.5) Other APIsLinq to XML DataSets

Query providers Out-of-the-box providers in.NET 3.5: –Linq to Objects –Linq to SQL Sources in query determine query providers –Affects keywords and operators you can use Query providers can translate Linq queries to some implementation Most providers come with Linq-enabled APIs –New object models to work with data –Linq to Objects has several: Linq to XML, DataSets

Demo Linq applied Scenario: WCF services using untyped Messages WPF Application WCF Service WCF proxy SOAP messages Linq to XML API Linq to SQL Linq to XML

New language features C# and VB Linq keywords Extension methods Lambda expressions Local variable inference Object and collection initializers Anonymous types Automatic properties Partial methods new

Visual Basic 9.0 Deep XML support –Express XPath axes with XML properties –Allows XML literals to appear inside of code root. Direct child elements Attribute selection doc... All descendants Dim fragment As XElement = _ Hedel

Visual Basic 9.0 –Gives you “expression holes” inside XML literals Additional keywords More freedom on order of keywords Dim query = _ From c In doc... _ Select > %> phone: (0) %>

Demo Visual Basic –WCF sample revisited –Deep XML support

Deferred execution Most Linq query providers are implemented using lazy evaluation Composed query expressions do not execute immediately Queries only execute when necessary –Performing an iteration over resultset –Using extension methods ToArray, ToList, ToLookup, ToDictionary –Using specific query operators, such as aggregates and set operators

More on deferred execution Before execution queries can still be changed or expanded –Adding additional sequence operators, such as Distinct, Skip, Take –Manipulating expression tree Expression trees are immutable Reference assignments take deep tree copies

Changes to way you write code Declarative –Far less looping constructs visible –Easier to read and to maintain Methods returning query or its results –Remember deferred execution –Force execution of query –Hand over query for further manipulation –Query reuse

Linq and architecture System.Data.Linq

Architecture recommendations Find out where and how your queries execute –Moment of execution –Local versus remote execution –Physical place/tier of query execution Keep queries inside assemblies –Do not pass query expressions between layers Anonymous types shouldn’t be return values –Think about important types up front –Use projections wisely

Other recommendations Learn: –to write queries with and without keywords –new language features Use whitepapers as reference –Translation of query keywords to operators –Evaluation details of operators Do not overuse or abuse var keyword –Decreases readability and stops you from thinking: if you know exact type, specify it –It sometimes takes more keystrokes

Runtimes and frameworks for Linq Linq to.NET FX 3.5Compact FX 3.5Silverlight 1.1 ObjectsXXX SQLX EntitiesX DataSetsXX XMLXXX providers APIs * ADO.NET Entity Framework released out of bounds with.NET FX 3.5 *

Beyond.NET FX 3.5 ADO.NET Entity Framework –Microsoft’s long-term vision on data –Brings query provider Linq to Entities Parallel Linq (PLinq) –Passes parts of query to different cores in multicore/multiproc machine Community query providers for Linq: –Linq to Amazon, LDAP, SharePoint, NHibernate, MySql, Flickr, … and more (to come) Linq 2.0

Expanding on Linq Linq-enable your existing API’s –Specifically for in-memory queries –Create extension methods that return an IEnumerable object Write your own query provider –Implement IQueryable –Parse expression trees and translate nodes to different code or query language

References Linq home page Future versions of –C#, Visual Basic, Visual StudioC#Visual BasicVisual Studio Recommended reading –Linq to XML beta 1 docsLinq to XML beta 1 docs –Future: Linq 2.0, PLinqLinq 2.0PLinq Downloads –Linq May 2006 CTP (for Visual Studio 2005)Linq May 2006 CTP –Visual Studio Orcas April 2007 Beta 1 and C#, VB samplesVisual Studio Orcas April 2007 Beta 1C#, VB samples –Reflector 5.0Reflector 5.0

Blogs Microsoft Teams –C#C# –VBVB –ADO.NETADO.NET Individuals on Linq –General: Oakleaf Systems, Wes Dyer, Jomo FisherOakleaf SystemsWes DyerJomo Fisher –SQL: Mike TaultyMike Taulty –XML: Eric WhiteEric White

Summary Linq is about query keywords and operators Linq will change way you write your code Linq to XML might be more important than you think Is VB a better query language than C#? Linq is extensible

Questions? ?