La descarga está en progreso. Por favor, espere

La descarga está en progreso. Por favor, espere

Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.

Presentaciones similares


Presentación del tema: "Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO."— Transcripción de la presentación:

1 Julián Enrique Verdezoto Celi

2 Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO

3 LINQ (Language Integrated Query) API de C# 3.0 focalizada en el acceso a datos. Múltiples origenes de datos. Extensibilidad SQL, XML y Objetos. Facilita relación datos objetos

4 Integración nativa con los lenguajes que facilitan la productividad y la detección de errores (Validación Sintáctica). Tipado anónimo para proyecciones en todo tipo de colecciones. Fuertemente Tipado.

5 Operadores de consulta pueden usarse en cualquier colección. Select, from, where, group by, join, etc. Sentencias para ordenamiento de datos.

6 OPERADORES DE CONSULTA var numbers = new int[] {1,2,5,8,12,13,14,15,17,21,23}; var results = from c in numbers where (c % 2) == 0 select c;

7 SENTENCIAS PARA ORDENAMIENTO static IEnumerable CrearEstudiantes() { return new List { new Estudiante { Nombre = "Juan", Carrera = "Derecho" }, new Estudiante { Nombre = "Ana", Carrera = "Sistemas" }, new Estudiante { Nombre = "Jenny", Carrera = "Turismo"} }; } var results = from c in CrearEstudiantes() where c.Carrera == "Sistemas“ orderby c.Nombre ascending select c;

8

9 Posee una API para XML sencilla y rápida. Facilita el trabajo con documentos XML, tanto de entrada como de salida.

10 XML consultas var doc = XDocument.Load(Server.MapPath("Customers.xml")); var results = from c in doc.Descendants("customer") where c.Element("city").Value == “London" select c;

11 XML creación de estructuras XElement transformedResults = new XElement("Clientes", from cust in results select new XElement("Contacto", new XAttribute("ID", cus.Element("id").Value), new XAttribute("Nombre", cus.Element("name").Value), new XAttribute("Ciudad", cus.Element("city").Value), new XAttribute("Pai", cus.Element("country").Value)));

12

13 Mapea una estructura SQL a una clase.Net Traduce una sentencia LINQ a SQL. Soporta operaciones de tipo insert, update y delete. DataContext, BD fuertemente tipadas. Soporte para jerarquías y relaciones. Chequeos en tiempo de compilación.

14 AplicattionAplicattion Dlinq(ADO.NET)Dlinq(ADO.NET) SQLServerSQLServer from c in db.Customers where c.City = “London” select new {c.Name, c.Phone } new {c.Name, c.Phone } from c in db.Customers where c.City = “London” select new {c.Name, c.Phone } new {c.Name, c.Phone } select Name, Phone from customers where city = ‘London’ select Name, Phone from customers where city = ‘London’ LINQ QueryObjects SubmitChanges() SQL QueryRowsSQL or Stores Procedures Services: Change tracking Change tracking Concurrency control Concurrency control Object identity Object identityServices: Change tracking Change tracking Concurrency control Concurrency control Object identity Object identity

15 DLINQ Designer

16 Relaciones entre entidades private System.Nullable _VEH_KILOMETRAJE; private string _VEH_COMENTARIO; private EntitySet _VHC_PARTEs; private EntityRef _VHC_MODELO; private EntityRef _VHC_PROPIETARIO;

17 Consulta grvVehiculos.DataSource = from veh in Vehiculos.VHC_VEHICULO join pro in dsPropietarios.VHC_PROPIETARIO on veh.PRP_ID equals pro.PRP_ID join mod in dsMarcas.VHC_MODELO on veh.MOD_ID equals mod.MOD_ID select new { VEH_ID = veh.VEH_ID, MAR_NOMBRE = mod.VHC_MARCARow.Mar_Nombre, MOD_NOMBRE = mod.MOD_NOMBRE, PRP_NOMBRES_APELLIDOS = pro.PRP_NOMBRES_APELLIDOS, VEH_ANIO_FABRICACION = veh.VEH_ANIO_FABRICACION, VEH_COLOR = veh.VEH_COLOR, VEH_CIUDAD = veh.VEH_CIUDAD, VEH_PRECIO = veh.VEH_PRECIO, VEH_KILOMETRAJE = veh.VEH_KILOMETRAJE, EXTRAS = veh.GetVHC_PARTERows().OrderBy(p => p.VHP_PARTE), NUMEXTRAS = veh.GetVHC_PARTERows().Count()};

18 Inserción VehiculosDataContext objVeh_DB = new VehiculosDataContext(); VHC_VEHICULO insVehiculo = new VHC_VEHICULO(); insVehiculo.MOD_ID = v.MOD_ID; insVehiculo.PRP_ID = (int)v.PRP_ID; insVehiculo.VEH_COLOR = v.VEH_COLOR; insVehiculo.VEH_CIUDAD = v.VEH_CIUDAD; insVehiculo.VEH_PRECIO = v.VEH_PRECIO; insVehiculo.VEH_KILOMETRAJE = (long)v.VEH_KILOMETRAJE; insVehiculo.VEH_COMENTARIO = v.VEH_COMENTARIO; objVeh_DB.VHC_VEHICULOs.Add(insVehiculo);

19 Actualización VehiculosDataContext objVeh_DB = new VehiculosDataContext(); var uptVehiculo = objVeh_DB.VHC_VEHICULOs.Single(p => p.VEH_ID == v.VEH_ID); uptVehiculo.MOD_ID = v.MOD_ID; uptVehiculo.PRP_ID = (int)v.PRP_ID; uptVehiculo.VEH_ANIO_FABRICACION = v.VEH_ANIO_FABRICACION; uptVehiculo.VEH_COLOR = v.VEH_COLOR; uptVehiculo.VEH_CIUDAD = v.VEH_CIUDAD; uptVehiculo.VEH_PRECIO = v.VEH_PRECIO; uptVehiculo.VEH_KILOMETRAJE = (long)v.VEH_KILOMETRAJE; uptVehiculo.VEH_COMENTARIO = v.VEH_COMENTARIO;

20 Eliminación VehiculosDataContext objVeh_DB = new VehiculosDataContext(); objVeh_DB.VHC_VEHICULOs.Remove( objVeh_DB.VHC_VEHICULOs.Single( p => p.VEH_ID == v.VEH_ID));

21

22 Soporta las funciones y Stored Procedures.

23 Reutilización de SPs objVeh_DB.InsertarMarcas(strNombre, strPais); objVeh_DB.ActualizarMarcas(intMarId, strNombre, strPais);

24

25 http://weblogs.asp.net/scottgu/ msdn2.microsoft.com/netframework/aa9045 94.aspx www.microsoft.com/spanish/msdn/articulos/ archivo/041206/voices/LINQ_Project.mspx blogs.microsoft.co.il/blogs/bursteg/archive/ta gs/VS2008/default.aspx

26 © 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.


Descargar ppt "Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO."

Presentaciones similares


Anuncios Google