SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Mariano Sánchez – Software Architect
marianos@lagash.com
Local variable
type inference

var contacts =
from c in customers
where c.State == "WA"
select new { c.Name, c.Phone };

Query
expressions

Lambda
expressions

var contacts =
customers
.Where(c => c.State == "WA")
.Select(c => new { c.Name, c.Phone });
Extension
methods

Anonymous
types

Object
initializers
public class List<T>
{
public List<T> Where(Func<T, bool> predicate) { … }
public List<S> Select<S>(Func<T, S> selector) { … }
…
}
List<Customer> customers = GetCustomerList();
List<string> contacts =
customers.Where(c => c.State == "WA").Select(c => c.Name);

Que pasa con
otros tipos?

Que pasa con los que
ya implementan IList?
Que pasa con
los arrays?

Operadores de
query son métodos

Componiendo
métodos
Query como
metodos estáticos

public static class Sequence
{
public static IEnumerable<T> Where<T>(IEnumerable<T> source,
Func<T, bool> predicate) { … }

public static IEnumerable<S> Select<T, S>(IEnumerable<T> source,
Func<T, S> selector) { … }
…
}

Hmmm…
Customer[] customers = GetCustomerArray();
IEnumerable<string> contacts = Sequence.Select(
Sequence.Where(customers, c => c.State == "WA"),
c => c.Name);

Sería bueno en
IEnumerable<T>
namespace System.Query
Extension
{
methods
public static class Sequence
{
public static IEnumerable<T> Where<T>(this IEnumerable<T> source,
Func<T, bool> predicate) { … }
public static IEnumerable<S> Select<T, S>(this IEnumerable<T> source,
Func<T, S> selector) { … }
…
}

Traigo las
extensiones

}
using System.Query;

IEnumerable<string> contacts =
customers.Where(c => c.State == "WA").Select(c => c.Name);

IntelliSense!

obj.Foo(x, y)

XXX.Foo(obj, x, y)
var contacts =
from c in customers
where c.State == "WA"
select new { c.Name, c.Phone };

var contacts =
customers
.Where(c => c.State == "WA")
.Select(c => new { c.Name, c.Phone });
Extension
methods

Query
expressions
int i = 5;
string s = "Hello";
double d = 1.0;
int[] numbers = new int[] {1, 2, 3};
Dictionary<int,Order> orders = new Dictionary<int,Order>();
var i = 5;
var s = "Hello";
var d = 1.0;
var numbers = new int[] {1, 2, 3};
var orders = new Dictionary<int,Order>();
Local variable
type inference

var contacts =
from c in customers
where c.State == "WA"
select new { c.Name, c.Phone };

var contacts =
customers
.Where(c => c.State == "WA")
.Select(c => new { c.Name, c.Phone });
public class Point
{
private int x, y;

public int X { get { return x; } set { x = value; } }
public int Y { get { return y; } set { y = value; } }
}
Point a = new Point { X = 0, Y = 1 };

Point a = new Point();
a.X = 0;
a.Y = 1;

Asignar campos
o propiedades
Debe implementar
ICollection<T>
List<int> powers = new List<int>{ 1, 10, 100, 1000, 10000 };
List<int> powers = new List<int>();
powers.Add(1);
powers.Add(10);
powers.Add(100);
powers.Add(1000);
powers.Add(10000);
var contacts =
from c in customers
where c.State == "WA"
select new { c.Name, c.Phone };

var contacts =
customers
.Where(c => c.State == "WA")
.Select(c => new { c.Name, c.Phone });
Object
initializers
public class Customer
{
public string Name;
public Address Address;
public string Phone;
public List<Order> Orders;
…
}

public class Contact
{
public string Name;
public string Phone;
}

Customer c = GetCustomer(…);
Contact x = new Contact { Name = c.Name, Phone = c.Phone };
Customer c = GetCustomer(…);
var x = new { Name = c.Name, Phone = c.Phone };

Customer c = GetCustomer(…);
var x = new { c.Name, c.Phone };
var contacts =
from c in customers
where c.State == "WA"
select new { c.Name, c.Phone };

var contacts =
customers.
.Where(c => c.State == "WA“)
.Select(c => new { c.Name, c.Phone });
foreach (var c in contacts) {
Console.WriteLine(c.Name);
Console.WriteLine(c.Phone);
}
var contacts =
from c in customers
where c.State == "WA"
select new { c.Name, c.Phone };

var contacts =
customers
.Where(c => c.State == "WA")
.Select(c => new { c.Name, c.Phone });
Anonymous
types
C# 3.0

VB 9.0

Others…

.NET Language Integrated Query

Standard
Query
Operators

Linq to Sql
(ADO.NET)

XLinq
(System.Xml)

<book>
<title/>
<author/>
<year/>
<price/>
</book>

Objects

SQL

XML
class Contact { … };
List<Contact> contacts = new List<Contacts>();
foreach(Customer c in customers)
{
if(c.State == “WA”)
{
Contact ct = new Contact();
ct.Name = c.Name;
ct.Phone = c.Phone;
contacts.Add(ct);
}
}
var contacts =
from c in customers
where c.State == "WA"
select new { c.Name, c.Phone };
try

catch
finally
try
catch
Restriction

Where, Contains

Projection

Select, SelectMany

Ordering

OrderBy, ThenBy

Grouping

GroupBy

Quantifiers

Any, All

Partitioning

Take, Skip, TakeWhile, SkipWhile

Sets

Distinct, Union, Intersect, Except

Elements

First, FirstOrDefault, ElementAt

Aggregation

Count, Sum, Min, Max, Average

Conversion

ToArray, ToList, ToDictionary

Casting

OfType<T>
demo

LINQ to SQL
• Mejorar la forma de procesar Xml





Creando nuevas instancias
Modificando instancias existentes
Consultando instancias en memoria
Combinando consultas entre Xml, Objetos y Datos
<

>
<

</
<

</

</
>

>
<
<
<
<

</
<
>
>
<
<
<

</
<
>

>

/
type= home >
type= work >
>
<
>
<
>
<
> </
<
>
>
> </

>

>
</
</
</
</

>
>
>
>

>
</

>

>
</

type= mobile >
>
<
>
<
>
<
> </
>
<
>
</
>
> </
>

>
</
</
</
>

>
>

>
XmlDocument
XmlElement

new XmlDocument
"name"
“Diego Gonzalez"

XmlElement

"phone"
"type" "home"
"206-555-0144"

XmlElement

XmlElement
"contact"

"phone"
"type" "work"
"425-555-0145"

XmlElement
"street1"
"123 Main St"

XmlElement

XmlElement
"contacts"

"city"
"Mercer Island"

XmlElement

"state"
"WA"

XmlElement
"postal"
"68042"
XmlElement
"address"
XElement
new XElement "contacts"
new XElement "contact"
new XElement "name" "Patrick Hines"
new XElement "phone" "206-555-0144"
new XAttribute "type" "home"
new XElement "phone" "425-555-0145"
new XAttribute "type" "work"
new XElement "address"
new XElement "street1" "123 Main St"
new XElement "city" "Mercer Island"
new XElement "state" "WA"
new XElement "postal" "68042"
var result = new XElement "contacts"
from
in
"contact"
select new
new XComment "contact"
new XElement "name"
string
"name"
"phone"
new XElement "address"
"address"
• Basado en un modelo conceptual
 Entity y EntitySet

• Se mapea con el modelo relacional de la base de datos

permitiendo abarcar mas escenarios.
Muchas Gracias

Mariano Sánchez – Software Architect
marianos@lagash.com

Weitere ähnliche Inhalte

Was ist angesagt?

The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88Mahmoud Samir Fayed
 
Type script by Howard
Type script by HowardType script by Howard
Type script by HowardLearningTech
 
Informatics Practices/ Information Practices Project (IP Project Class 12)
Informatics Practices/ Information Practices Project (IP Project Class 12)Informatics Practices/ Information Practices Project (IP Project Class 12)
Informatics Practices/ Information Practices Project (IP Project Class 12)KushShah65
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by HowardLearningTech
 
Data oriented design
Data oriented designData oriented design
Data oriented designMax Klyga
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2rohassanie
 

Was ist angesagt? (13)

C++ Template
C++ TemplateC++ Template
C++ Template
 
The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88
 
Type script by Howard
Type script by HowardType script by Howard
Type script by Howard
 
Informatics Practices/ Information Practices Project (IP Project Class 12)
Informatics Practices/ Information Practices Project (IP Project Class 12)Informatics Practices/ Information Practices Project (IP Project Class 12)
Informatics Practices/ Information Practices Project (IP Project Class 12)
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
 
Data oriented design
Data oriented designData oriented design
Data oriented design
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
Template C++ OOP
Template C++ OOPTemplate C++ OOP
Template C++ OOP
 
Templates
TemplatesTemplates
Templates
 
Container adapters
Container adaptersContainer adapters
Container adapters
 
Unit 4 (1)
Unit 4 (1)Unit 4 (1)
Unit 4 (1)
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
Templates
TemplatesTemplates
Templates
 

Ähnlich wie Introducción a LINQ

Linq 090701233237 Phpapp01
Linq 090701233237 Phpapp01Linq 090701233237 Phpapp01
Linq 090701233237 Phpapp01google
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05CHOOSE
 
Share pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbsShare pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbsShakir Majeed Khan
 
Linq Sanjay Vyas
Linq   Sanjay VyasLinq   Sanjay Vyas
Linq Sanjay Vyasrsnarayanan
 
Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#Vagif Abilov
 
C# 3.0 Language Innovations
C# 3.0 Language InnovationsC# 3.0 Language Innovations
C# 3.0 Language InnovationsShahriar Hyder
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfarihantmum
 
Advanced dot net
Advanced dot netAdvanced dot net
Advanced dot netssa2010
 
C# Starter L04-Collections
C# Starter L04-CollectionsC# Starter L04-Collections
C# Starter L04-CollectionsMohammad Shaker
 
Sqlforetltesting 130712042826-phpapp01
Sqlforetltesting 130712042826-phpapp01Sqlforetltesting 130712042826-phpapp01
Sqlforetltesting 130712042826-phpapp01Gyanendra Kumar
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012Sandeep Joshi
 

Ähnlich wie Introducción a LINQ (20)

Linq 090701233237 Phpapp01
Linq 090701233237 Phpapp01Linq 090701233237 Phpapp01
Linq 090701233237 Phpapp01
 
Introduction to Linq
Introduction to LinqIntroduction to Linq
Introduction to Linq
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
 
Share pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbsShare pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbs
 
Linq Sanjay Vyas
Linq   Sanjay VyasLinq   Sanjay Vyas
Linq Sanjay Vyas
 
Greg Demo Slides
Greg Demo SlidesGreg Demo Slides
Greg Demo Slides
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#
 
PostThis
PostThisPostThis
PostThis
 
Linq intro
Linq introLinq intro
Linq intro
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
C# 3.0 Language Innovations
C# 3.0 Language InnovationsC# 3.0 Language Innovations
C# 3.0 Language Innovations
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdf
 
Dat402
Dat402Dat402
Dat402
 
Advanced dot net
Advanced dot netAdvanced dot net
Advanced dot net
 
Lesson11
Lesson11Lesson11
Lesson11
 
C# Starter L04-Collections
C# Starter L04-CollectionsC# Starter L04-Collections
C# Starter L04-Collections
 
Sqlforetltesting 130712042826-phpapp01
Sqlforetltesting 130712042826-phpapp01Sqlforetltesting 130712042826-phpapp01
Sqlforetltesting 130712042826-phpapp01
 
SQL for ETL Testing
SQL for ETL TestingSQL for ETL Testing
SQL for ETL Testing
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 

Mehr von Mariano Sánchez

Mehr von Mariano Sánchez (18)

.NET Core
.NET Core.NET Core
.NET Core
 
ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0
 
Introducción a SignalR
Introducción a SignalRIntroducción a SignalR
Introducción a SignalR
 
Visual Studio LightSwitch
Visual Studio LightSwitchVisual Studio LightSwitch
Visual Studio LightSwitch
 
HTML5 + Asp.NET
HTML5 + Asp.NETHTML5 + Asp.NET
HTML5 + Asp.NET
 
Hey Cortana!
Hey Cortana!Hey Cortana!
Hey Cortana!
 
Developing Universal Apps for Windows
Developing Universal Apps for WindowsDeveloping Universal Apps for Windows
Developing Universal Apps for Windows
 
Introducing the Windows Phone 8.1 App Development Platform
Introducing the Windows Phone 8.1 App Development PlatformIntroducing the Windows Phone 8.1 App Development Platform
Introducing the Windows Phone 8.1 App Development Platform
 
Visual Studio Online
Visual Studio OnlineVisual Studio Online
Visual Studio Online
 
Patrones Grasp
Patrones GraspPatrones Grasp
Patrones Grasp
 
Patrones de Diseño
Patrones de DiseñoPatrones de Diseño
Patrones de Diseño
 
Introducción a DDD
Introducción a DDDIntroducción a DDD
Introducción a DDD
 
Conociendo TypeScript
Conociendo TypeScriptConociendo TypeScript
Conociendo TypeScript
 
C# 6 - Que hay de nuevo?
C# 6 - Que hay de nuevo?C# 6 - Que hay de nuevo?
C# 6 - Que hay de nuevo?
 
Universal Windows Platform Programando para todos y todas
Universal Windows PlatformProgramando para todos y todasUniversal Windows PlatformProgramando para todos y todas
Universal Windows Platform Programando para todos y todas
 
Code Smells
Code SmellsCode Smells
Code Smells
 
Refactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existenteRefactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existente
 
Patrones de Diseño
Patrones de DiseñoPatrones de Diseño
Patrones de Diseño
 

Kürzlich hochgeladen

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 

Kürzlich hochgeladen (20)

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 

Introducción a LINQ

  • 1. Mariano Sánchez – Software Architect marianos@lagash.com
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. Local variable type inference var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone }; Query expressions Lambda expressions var contacts = customers .Where(c => c.State == "WA") .Select(c => new { c.Name, c.Phone }); Extension methods Anonymous types Object initializers
  • 7. public class List<T> { public List<T> Where(Func<T, bool> predicate) { … } public List<S> Select<S>(Func<T, S> selector) { … } … } List<Customer> customers = GetCustomerList(); List<string> contacts = customers.Where(c => c.State == "WA").Select(c => c.Name); Que pasa con otros tipos? Que pasa con los que ya implementan IList? Que pasa con los arrays? Operadores de query son métodos Componiendo métodos
  • 8. Query como metodos estáticos public static class Sequence { public static IEnumerable<T> Where<T>(IEnumerable<T> source, Func<T, bool> predicate) { … } public static IEnumerable<S> Select<T, S>(IEnumerable<T> source, Func<T, S> selector) { … } … } Hmmm… Customer[] customers = GetCustomerArray(); IEnumerable<string> contacts = Sequence.Select( Sequence.Where(customers, c => c.State == "WA"), c => c.Name); Sería bueno en IEnumerable<T>
  • 9. namespace System.Query Extension { methods public static class Sequence { public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate) { … } public static IEnumerable<S> Select<T, S>(this IEnumerable<T> source, Func<T, S> selector) { … } … } Traigo las extensiones } using System.Query; IEnumerable<string> contacts = customers.Where(c => c.State == "WA").Select(c => c.Name); IntelliSense! obj.Foo(x, y)  XXX.Foo(obj, x, y)
  • 10. var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone }; var contacts = customers .Where(c => c.State == "WA") .Select(c => new { c.Name, c.Phone }); Extension methods Query expressions
  • 11. int i = 5; string s = "Hello"; double d = 1.0; int[] numbers = new int[] {1, 2, 3}; Dictionary<int,Order> orders = new Dictionary<int,Order>(); var i = 5; var s = "Hello"; var d = 1.0; var numbers = new int[] {1, 2, 3}; var orders = new Dictionary<int,Order>();
  • 12. Local variable type inference var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone }; var contacts = customers .Where(c => c.State == "WA") .Select(c => new { c.Name, c.Phone });
  • 13. public class Point { private int x, y; public int X { get { return x; } set { x = value; } } public int Y { get { return y; } set { y = value; } } } Point a = new Point { X = 0, Y = 1 }; Point a = new Point(); a.X = 0; a.Y = 1; Asignar campos o propiedades
  • 14. Debe implementar ICollection<T> List<int> powers = new List<int>{ 1, 10, 100, 1000, 10000 }; List<int> powers = new List<int>(); powers.Add(1); powers.Add(10); powers.Add(100); powers.Add(1000); powers.Add(10000);
  • 15. var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone }; var contacts = customers .Where(c => c.State == "WA") .Select(c => new { c.Name, c.Phone }); Object initializers
  • 16. public class Customer { public string Name; public Address Address; public string Phone; public List<Order> Orders; … } public class Contact { public string Name; public string Phone; } Customer c = GetCustomer(…); Contact x = new Contact { Name = c.Name, Phone = c.Phone }; Customer c = GetCustomer(…); var x = new { Name = c.Name, Phone = c.Phone }; Customer c = GetCustomer(…); var x = new { c.Name, c.Phone };
  • 17. var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone }; var contacts = customers. .Where(c => c.State == "WA“) .Select(c => new { c.Name, c.Phone }); foreach (var c in contacts) { Console.WriteLine(c.Name); Console.WriteLine(c.Phone); }
  • 18. var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone }; var contacts = customers .Where(c => c.State == "WA") .Select(c => new { c.Name, c.Phone }); Anonymous types
  • 19. C# 3.0 VB 9.0 Others… .NET Language Integrated Query Standard Query Operators Linq to Sql (ADO.NET) XLinq (System.Xml) <book> <title/> <author/> <year/> <price/> </book> Objects SQL XML
  • 20. class Contact { … }; List<Contact> contacts = new List<Contacts>(); foreach(Customer c in customers) { if(c.State == “WA”) { Contact ct = new Contact(); ct.Name = c.Name; ct.Phone = c.Phone; contacts.Add(ct); } } var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone };
  • 21.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. Restriction Where, Contains Projection Select, SelectMany Ordering OrderBy, ThenBy Grouping GroupBy Quantifiers Any, All Partitioning Take, Skip, TakeWhile, SkipWhile Sets Distinct, Union, Intersect, Except Elements First, FirstOrDefault, ElementAt Aggregation Count, Sum, Min, Max, Average Conversion ToArray, ToList, ToDictionary Casting OfType<T>
  • 30.
  • 31. • Mejorar la forma de procesar Xml     Creando nuevas instancias Modificando instancias existentes Consultando instancias en memoria Combinando consultas entre Xml, Objetos y Datos
  • 32. < > < </ < </ </ > > < < < < </ < > > < < < </ < > > / type= home > type= work > > < > < > < > </ < > > > </ > > </ </ </ </ > > > > > </ > > </ type= mobile > > < > < > < > </ > < > </ > > </ > > </ </ </ > > > >
  • 33. XmlDocument XmlElement new XmlDocument "name" “Diego Gonzalez" XmlElement "phone" "type" "home" "206-555-0144" XmlElement XmlElement "contact" "phone" "type" "work" "425-555-0145" XmlElement "street1" "123 Main St" XmlElement XmlElement "contacts" "city" "Mercer Island" XmlElement "state" "WA" XmlElement "postal" "68042" XmlElement "address"
  • 34. XElement new XElement "contacts" new XElement "contact" new XElement "name" "Patrick Hines" new XElement "phone" "206-555-0144" new XAttribute "type" "home" new XElement "phone" "425-555-0145" new XAttribute "type" "work" new XElement "address" new XElement "street1" "123 Main St" new XElement "city" "Mercer Island" new XElement "state" "WA" new XElement "postal" "68042"
  • 35. var result = new XElement "contacts" from in "contact" select new new XComment "contact" new XElement "name" string "name" "phone" new XElement "address" "address"
  • 36.
  • 37. • Basado en un modelo conceptual  Entity y EntitySet • Se mapea con el modelo relacional de la base de datos permitiendo abarcar mas escenarios.
  • 38.
  • 39.
  • 40. Muchas Gracias Mariano Sánchez – Software Architect marianos@lagash.com