1 / 29

Language Integrated Query

Language Integrated Query. Johnny Halife Microsoft Student Ambassador Southworks. 5 Stored Procedures. Sistema. Objeto. DataAccess. Recursos. Un problema práctico. Agenda. Qué es LINQ? Standard Query Operations DLINQ Conclusiones. Qué es LINQ? La programación hoy en día.

filia
Télécharger la présentation

Language Integrated Query

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Language Integrated Query Johnny Halife Microsoft Student Ambassador Southworks

  2. 5 Stored Procedures Sistema Objeto DataAccess Recursos Un problema práctico

  3. Agenda • Qué es LINQ? • Standard Query Operations • DLINQ • Conclusiones

  4. Qué es LINQ?La programación hoy en día • Desarrollo Orientado a Objetos • Datos en tecnologías no OO. • Distintos entornos de Desarrollo • No Intellisense, late bound, verbose • T-SQL vs. .NET Framework • “Impedance Mismatch” Programming World Database World Transactions Nulls - 3-value logic Normalized Data Declarative Queries Transparency Exception Handling “Different” nulls Objects Imperative operations Encapsulation

  5. <book> <title/> <author/> <year/> <price/> </book> SQL WinFS Objects XML The LINQ Project C# VB Others… .NET Language Integrated Query StandardQueryOperators DLinq(ADO.NET) XLinq (System.Xml)

  6. Services:- Change tracking- Concurrency control- Object identity SQL or Stored Procs Rows SQLServer Application DLinq(ADO.NET) Arquitectura from c in db.Customerswhere c.City == "London"select new { c.Name, c.Phone } Objects LINQ Query SubmitChanges() SQL Query select Name, Phonefrom customerswhere city = 'London'

  7. Una consulta hoy en día Queries entre comillas 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("@po", "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(); Argumentos literales Resultados no tipados No hay checkeos en compilación

  8. Una consulta con LINQ Clases que describen tablas public class Customer { public int Id; public string Name; public string Phone; … } Table<Customer> customers = db.Customers; var contacts = from c in customers where c.City == "London" select new { c.Name, c.Phone }; Las tablas son colecciones El query es nativo del lenguaje Validación en tiempo de compilación

  9. Demostracion #1 Una consulta con LINQ

  10. En qué esta basado LINQ? • En las innovaciones introducidas por C# 2.0 y C# 3.0

  11. Objetivos de C# 3.0 Integración de OOP, Relacional y Xml. Basarse en los fundamentos de C# 2.0. No atar los lenguajes a APIS especificos. Compatibilidad hacia atrás.

  12. En qué esta basado LINQ?Innovaciones C# 3.0 • Métodos de Extensión • Agregar metodos a clases (incluso selladas) • Notación de cascada de puntos (tipica en OOP) • Fácil de escribir • Expresiones Lambda • Notación más clara y funcional • Se pueden omitir los tipos de datos, se infieren. • Puede ser una expresión o una secuencia de sentencias • Inicialización de Objetos • Ya no es necesario declarar tantas sobrecargas del c’tor como inicializaciones posibles hay del objeto. • Inicialización de Collections • Tipos Anónimos • Sirven para el resultado de las querys • Inferencia de Tipos • Codificación más clara • Posibilidad de trabajar con tipos anónimos

  13. Demostracion #2 C# 3.0 Features

  14. Agenda • Qué es LINQ? • Standard Query Operations • DLINQ • Conclusiones

  15. Standard Query OperationsAccediendo Objetos con LINQ • Expresiones de Consulta con LINQ EMPIEZACONfrom SEGUIDO DE CEROo MASfromowhere fromidinsource { fromidinsource | wherecondition } [ orderbyordering, ordering, … ] selectexpr | groupexprbykey [ intoidquery ] orderby OPCIONAL TERMINA CON UNselecto CON UNgroup by PUEDE CONTINUAR CON UNinto

  16. Operaciones de Consulta de LINQ

  17. Demostracion #3 Usando métodos de consulta

  18. Agenda • Qué es LINQ? • Standar Query Operations • DLINQ • Conclusiones

  19. DLINQDatos Relacionales con DLINQ • Mapeo a través de atributos • Mapeo manual o automatico (built-in tool) • Persistencia • Control de cambios automático • DataContext • Bases de Datos fuertemente tipadas

  20. Demostracion #3 Accediendo a datos relacionales con DLINQ

  21. Caracteristicas • Language Integrated Query • Checkeos en tiempo de compilación, IntelliSense • Sintaxsis tipo SQL • Soporte para jerarquias y relaciones • Carga de objetos inteligentes • Lazy o Inmediata

  22. Demostracion #4 Relaciones con LINQ

  23. Caracteristicas • Updates automaticos • Usando optimistic concurrency • Transactions • Integradas con System.Transactions

  24. Demostracion #5 Updates usando DLINQ

  25. Conclusiones

  26. Demostracion #7 Poniendo todo junto….

  27. Para más información • Data Access and Storage Developer Center: The LINQ Project • http://msdn.microsoft.com/netframework/future/linq/ • C# 3.0 Hands On Lab • LINQ Hands On Lab • http://staff.southworks.net/blogs/johnny • http://www.ajlopez.net

  28. Preguntas

More Related