DEV306 LINQ (Language Integrated Query)

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

Language Integrated Query (LINQ) Martin Parry Developer & Platform Group Microsoft Ltd
Michael Pizzo Software Architect Data Programmability Microsoft Corporation.
© Logica All rights reserved ADO vNext LINQ LINQ to SQL Entity Framework Freek Leemhuis
Joshua Clark Consultant Sogeti USA Blog:
Live from Redmond: WebCast Conquering XML with Visual Basic 9 Amanda Silver Lead Program Manager Visual Basic Level: Starts Easy, Finishes Advanced.
Overview of Next-gen technologies Raimond Brookman IT Architect Info Support
ASP.NET 3.5 New Features. 2 Agenda What's New in.NET Framework 3.5? Visual Studio 2008 Enhancements LINQ (Language Integrated Query) New ASP.NET Server.
C# 3.0 & LINQ Raimond Brookman – IT Architect
LinqToSharePoint SandBoxed Solution Shakir Majeed Khan
Damien Guard (BSc, MBCS) Guernsey Software Developer Forum Language Integrated Query:
Introduction to Database Processing with ADO.NET.
1 Agenda Data and System Trends ChallengesObservationsConclusion.
Building a Complete Web Application Using ASP.NET 3.5 & Visual Studio 2008 (Part 1 of 2) Jeff King Program Manager Microsoft Corporation
The Microsoft Technical Roadshow 2007 Advances for Data in VS “Orcas” Mike Taulty Developer & Platform Group Microsoft Ltd
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
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.
Paul Yuknewicz Lead Program Manager Microsoft Visual Basic DEV 319.
Some Basic Database Terminology
LINQ Programming in C# LINQ CSE Prof. Roger Crawfis.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
Slides from Gang Luo, Xuting Zhao and Damien Guard
Reflection IT LINQ & Entity Framework Fons Sonnemans (Trainer)
LINQ Boot Camp ADO.Net Entity Framework Presenter : Date : Mahesh Moily Nov 26, 2009.
Entity Framework, a quickstart Florin−Tudor Cristea, Microsoft Student Partner.
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
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 and C# 3.0 Mads Torgersen Program Manager for the C# Language Microsoft Corporation.
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.
File Processing Concepts – Field – combination of 1 or more characters that is the smallest unit of data to be accessed – Record – group of related fields.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
Välkommen till Sommarkollo VISUAL STUDIO 2008.
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
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.
Creating and Maintaining Geographic Databases. Outline Definitions Characteristics of DBMS Types of database Relational model SQL Spatial databases.
AUC Technologies LINQ (Language Integrated Query) LINQ Presented By : SHAIKH SHARYAR JAVED Software Engineer (Daedalus Software Inc.) Technology Teacher.
Language Integrated Query (LINQ). Data Access Programming Challenges Developers must learn data store-specific query syntax Multiple, disparate data stores.
By: Luis Carranco CIS764 - Fall  What is LINQ  Architecture  How does it work?  Samples/Demo  Why to use LINQ? 2.
C#: Future Directions in Language Innovation Anders Hejlsberg TLN307 Technical Fellow Microsoft Corporation.
Applied Linq Putting Linq to work Introducing… Class-A Kennisprovider Microsoft development Training Coaching Alex Thissen Trainer/coach.
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
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:
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.
2 Behind every great site, there is great data Eric Nelson Developer Evangelist Microsoft UK
Data Access Methodologies: When to choose what (ADO.NET, Entity Framework, WCF Data Services) Wriju Ghosh Lead Partner Consultant, Microsoft.
Jon JahrenJon Jahren Produktsjef, Microsoft NorgeProduktsjef, Microsoft Norge
Top 10 Entity Framework Features Every Developer Should Know
Introduction to Database Processing with ADO.NET
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
ADO.NEXT Advances in Data Access for 2008
Language Integrated Query (LINQ)
Data Model.
Chapter 10 ADO.
Технологии доступа к данным на платформе Microsoft.NET
ADO.NET Entity Framework
9/8/ :03 PM © 2006 Microsoft Corporation. All rights reserved.
Presentation transcript:

DEV306 LINQ (Language Integrated Query) Frank Maar frank.maar@microsoft.com Technologieberater Visual Studio Microsoft Deutschland GmbH

Problem: Data != Objects

Customer Requirements Database applications need to be able to evolve from the current model. We can’t force them to choose between throwing away code and using the great new stuff. ODBC, DAO, RDO, OLEDB, ADO, ADO.NET ISV’s always end up building boats over us Data is everywhere and fundamentally structured. Understanding that structure is takes time from coding Programming teams want to work in their domain area Financial, Oil, Retail – different understanding of “Customer” Intermediate storage for in-memory, embedded caches Programmers want those caches close to their code

EDB/IMDB Product Pressure SQL Server Enterprise Edition SQL Server Express Deployment Complexity EDB / IMDB If you look at the spectrum of embedded structures to support data programming starting with data structures and progressing in complexity to servers, clusters and someday grids each product fits a specific space and brings with it a cooresponding level of deployment complexity. Today there is customer pressure both on dataset from below to add scalability, persistence, and generalized query capabilities, while we have pressure to push the SQL Server Express SKU down to ease deployment especially with rich client or mid-tier applications. PRODUCT GAP PRESSURE Dataset Data Structure Process Application Server Cluster Grid

.NET Language Integrated Query The LINQ Project C# 3.0 VB 9.0 Others… .NET Language Integrated Query LINQ to Objects LINQ to DataSets LINQ to SQL LINQ to Entities LINQ to XML <book> <title/> <author/> <year/> <price/> </book> XML Relational Objects

Project Linq VB & C # language extensions Base query operators DLinq Enable creation of higher-order APIs Base query operators API for querying arbitrary data structures DLinq Query enabled Object-Relational API XLinq Query enabled, modern, consistent XML API

LINQ Restriction Where Projection Select, SelectMany Ordering OrderBy, ThenBy Grouping GroupBy Joins Join, GroupJoin Quantifiers Any, All Partitioning Take, Skip, TakeWhile, SkipWhile Sets Distinct, Union, Intersect, Except Elements First, Last, Single, ElementAt Aggregation Count, Sum, Min, Max, Average Conversion ToArray, ToList, ToDictionary Casting OfType<T>, Cast<T>

LINQ to SQL Accessing data today Queries in quotes SqlConnection c = new SqlConnection(…); c.Open(); SqlCommand cmd = new SqlCommand( @"SELECT c.Name, c.Phone FROM Customers c WHERE c.City = @p0"); cmd.Parameters.AddWithValue("@p0", "London“); DataReader dr = c.Execute(cmd); while (dr.Read()) { string name = dr.GetString(0); string phone = dr.GetString(1); DateTime date = dr.GetDateTime(2); } dr.Close(); Loosely bound arguments Loosely typed result sets No compile time checks

LINQ to SQL Accessing data with LINQ Classes describe data public class Customer { … } public class Northwind : DataContext { public Table<Customer> Customers; … } Tables are like collections Strongly typed connections Northwind db = new Northwind(…); var contacts = from c in db.Customers where c.City == "London" select new { c.Name, c.Phone }; Integrated query syntax Strongly typed results

LINQ to SQL Language integrated data access Mapping Persistence Maps tables and rows to classes and objects Builds on ADO.NET and .NET Transactions Mapping Encoded in attributes or external XML file Relationships map to properties Persistence Automatic change tracking Updates through SQL or stored procedures

LINQ to SQL Mapping Database DataContext Table Class View Class Column Field / Property Relationship Field / Property Stored Procedure Method

LINQ to SQL Architecture Application from c in db.Customers where c.City == "London" select c.CompanyName db.Customers.Add(c1); c2.City = "Barcelona"; db.Customers.Remove(c3); LINQ Query Objects SubmitChanges() LINQ to SQL SQL Query Rows DML or SProcs SELECT CompanyName FROM Cust WHERE City = 'London' INSERT INTO Cust … UPDATE Cust … DELETE FROM Cust … SQL Server

Key Points Flexible mapping DataContext Entity classes Relationships “Classes first” or “data first”, attributes or mapping file DataContext Strongly typed database connection Entity classes Identity mapping and change tracking Relationships One-to-one, one-to-many

Key Points Change tracking Optimistic concurrency Stored procedures Updates through dynamic SQL DML or stored procedures Optimistic concurrency Stored procedures Represented as methods on DataContext Dynamic queries Expression trees and dynamic parser

Oracle Oracle driver from Oracle and DataDirect The DataDirect driver is expected to be available within a couple months of the LINQ release We expect that the Oracle driver will be more along the lines of 6-12 months after the release

Third-party languages Delphi http://blogs.borland.com/dcc/archive/2005/09/15/21195.aspx Phalanger 2.0 PHP compiler for .NET, LINQ syntax per "PHP/CLR - Extensions to the PHP Language in Phalanger 2.0“ http://www.codeplex.com/Phalanger/Wiki/View.aspx?title=Documentation) Nemerle macros being developed per http://thread.gmane.org/gmane.comp.lang.nemerle.devel/1257

LINQ to XML Programming XML today Imperative model XmlDocument doc = new XmlDocument(); XmlElement contacts = doc.CreateElement("contacts"); foreach (Customer c in customers) if (c.Country == "USA") { XmlElement e = doc.CreateElement("contact"); XmlElement name = doc.CreateElement("name"); name.InnerText = c.CompanyName; e.AppendChild(name); XmlElement phone = doc.CreateElement("phone"); phone.InnerText = c.Phone; e.AppendChild(phone); contacts.AppendChild(e); } doc.AppendChild(contacts); Document centric No integrated queries Memory intensive <contacts> <contact> <name>Great Lakes Food</name> <phone>(503) 555-7123</phone> </contact> … </contacts>

LINQ to XML Programming XML with LINQ Declarative model XElement contacts = new XElement("contacts", from c in customers where c.Country == "USA" select new XElement("contact", new XElement("name", c.CompanyName), new XElement("phone", c.Phone) ) ); Element centric Integrated queries Smaller and faster

Key Points Identity mapping Relationships Ad hoc joins Maps primary keys onto object references Relationships Pre-defined joins, lazy or eager fetching Ad hoc joins Inner joins and grouped joins Deferred execution Cost-free query composition

ADO.NET V3 in Orcas Language integrated data access Mapping 4/14/2017 ADO.NET V3 in Orcas Language integrated data access Maps tables and rows to classes and objects Extends ADO.NET - provider, dataset, mapping, object layers Works well with .NET Transactions Mapping Declarative approach promoting reuse, evolution Relationships map to properties Supports containment vs. association Starting point for metadata infrastructure Consistent update and query views for mapping Persistence and identity management Automatic change tracking Updates through SQL or stored procs *

Deep Technical Foundation Based on 30 years of product and research experience Proven - view maintenance technology Scales - multiplicative complexity of mapping Bidirectional views – update/query symmetry Grounded on relational technology Performance and Scalability Must live up to SQL Server’s birthright and customer expectation Avoid Hidden Cliffs in Query Processing Must include real-world enterprise software scenarios

Sample: Simple Query Dim primes = {2, 5, 7, 11, 13, 15} Dim primesUnder9 = Select p From p In primes Where p < 9   ‘ To display the results For Each num In PrimesUnder9 Console.Writeline(“Num: “ & num) Next Stop

Sample: Interesting Query ‘ To query Dim tasks = Select proc.ProcessName, proc.ID _ From proc In System.Diagnostics.Process.GetProcesses()_ Where proc.Threads.Count > 6   ‘ To display For each task In Tasks Console.Writeline(“Name : “ & task.ProcessName & _ “ ID: “ & task.ID) Next Stop

LINQ to SQL Select

LINQ to SQL Update and Delete

Challenges Around LINQ Performance of brute-force query execution across moderate-size in-memory collections can be bad very quickly Brute-force Joins are implemented as nested loops – O(size(T1)*size(T2)). Performance slow-down noticeable even in collections containing a few hundred rows. There are well know execution strategies O(size(T1)+size(T2))  May need a light weight QP to exploit

Empfehlungen Visual Studio 2008 (Orcas) Beta 2 VPC herunterladen und mit LINQ vertraut machen Bestehende Anwendungen so lassen Neue Anwendungen ab 2.Quartal 2008 LINQ nutzen Selbst entwickeltes objektrelationales Mapping entfällt

©. 2006 Microsoft Corporation. All rights reserved © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.