1 Bienvenidos
2 Language Integrated Query – LINQ: Nuevos paradigmas en el acceso a datosOscar J. Berroterán MCP, MVP Visual Basic,Ineta Academic Speaker, MS Andean Speaker Group
3 Agenda Pasado, presente y futuro Objetivos Presentando LINQ Demos
4 .Net a través del tiempo 2002 2003 2005 2006 2008¿? Tool(Visual Studio) VS .NET 2002 VS .NET 2003 VS .NET 2005 + Extensiones (WPF, WWF,..) Visual Studio 2008 Codename Orcas Lenguajes C# v1 VB .Net v7 C# v1.1 VB .Net v7.1 C# v2 VB 2005 (v8) C# v3 VB .9 Framework NetFx v1.0 NetFx v1.1 NetFx v2.0 NetFx v3.0 NetFx v3.5 Engine (CLR) CLR v1.0 CLR v1.1 CLR v2.0 ¿?
5 Evolución de acceso a datos en .NetWPF,WCF, WWF .Net 3.0 .Net 2.0 Generics ADO .Net Factory objects .Net 1.0 ADO .Net , Datasets (desconectado), Componentes administrados
6 El concepto … “El concepto LINQ es la idea de aportar al .Net Framework la capacidad de creación, generación y ejecución de un modelo de consulta sobre cualquier tipo de información en memoria.” Datos Objetos != Orientación a objeto, polimorfismo, interfaces, herencia… Proyecciones, agrupaciones, claves foráneas, joins…
7 Objetivos de LINQ Integración de datos Adicional ObjetosDatos Relacionales XML Adicional Mejorar la consistencia de los lenguajes Añadir funcionalidad No atar el lenguaje a un API especifico Mantener la compatibilidad hacia atras
8 Objetivos de LINQ Simplificar la búsqueda de informaciónIntegrar búsquedas y transformaciones Unificar el proceso de búsqueda en diferentes fuentes de información Simplificar el trabajo con XML Producir docs. XML rápidamente Accecer a los miembros de un doc. XML fácilmente
9 mmm, ¿Cómo? Sintaxis LINQ From C in ClientesWhere c.Ciudad = “Maracay” Select new { c.Nombre, c.Apellido}; Sintaxis SQL Select C.Nombre, c.Apellido from Clientes As c where c.Ciudad=“Maracay”;
10 Presentando Language Integrated Query (LINQ)C# VB Others… .Net Language Integrated Query (LINQ) LINQ enabled data sources LINQ to ADO.NET LINQ To Objects LINQ To Datasets LINQ To SQL LINQ To Entities LINQ To XML
11 ¿Que hay detrás de esto? Mejoras del lenguaje = L I N Q(Inferencia de tipos Inicializadores de objetos Tipos anónimos Expresiones Lambda (funciones en línea) Extension Methods) + Query Expressions = L I N Q
12 Sintaxis From id in Source {From id in Source|Cero o más From, join, let, where u orderby Comienza con From From id in Source {From id in Source| Join id in Source on expr equals expr [into id]| Let id = expr| where condition | Orderby ordering, ordering,…} Select expr | group expr by key Into idquery Termina con Select o groupby Continuación opcional into
13 Local Variable Type InferenceEl tipo de la variable se determina del proceso de inicialización Dim i=666 Dim s = “UCAB” Dim d = 3.14 Dim numbers = new int() {1,2,3,4}
14 Object Initializers Dim oPunto as Punto = New Punto oPunto.X=10Public Class Punto Private mX as integer Private mY as integer Public Property X as Integer Get Return mX end get Set (ByVal value as Integer) mX=value end Set End Property End Class Dim oPunto as Punto = New Punto oPunto.X=10 oPunto.Y=20 Dim Opunto as Point = New Point With {.X=10, .Y=20}
15 Lambda Expresions Una expresión lambda es una función sin nombre que calcula y devuelve un solo valor. Las expresiones lambda se pueden utilizar dondequiera que un tipo del delegado sea válido. Método Clase real X=Paises.GetAll.Where(Function (a as Paises) a.Id =1) Ext. Method
16 Anonymous Types Class XXX Public Nombre as String Public Tipo as Integer End Class XXX Dim OCliente = New With {.Nombre=“Oscar”, .Tipo=20}
17 12/7/2017 4:44 AM Extension Methods Los métodos de extensión permiten, a partir de la creación de clases, extender tipos existentes con nuevas funcionalidades (métodos). En VB9 sólo estan permitidos a nivel de módulos
18 demo Linq to Objects 12/7/2017 4:44 AM© 2007 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.
19 Language INtegrated Query12/7/2017 4:44 AM Language INtegrated Query C# VB Others… .Net Language Integrated Query (LINQ) LINQ enabled data sources LINQ enabled ADO.NET LINQ To Objects LINQ To Datasets LINQ To SQL LINQ To Entities LINQ To XML
20 12/7/2017 4:44 AM demo Linq to SQL © 2007 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.
21 Recursos Visual Studio 2008 LINQ Forum LINQ project12/7/2017 4:44 AM Recursos Visual Studio 2008 LINQ Forum teID=1 LINQ project Blogs © 2007 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.
22 12/7/2017 4:44 AM GRACIAS !!! © 2007 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.