Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y...
-
Upload
jose-aleman -
Category
Documents
-
view
147 -
download
3
Transcript of Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y...
![Page 1: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/1.jpg)
Julián Enrique Verdezoto Celi
![Page 2: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/2.jpg)
Conceptos Generales
LINQ en objetos DEMO
LINQ y XML DEMO
LINQ y SQL DEMO
![Page 3: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/3.jpg)
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
![Page 4: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/4.jpg)
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.
![Page 5: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/5.jpg)
Operadores de consulta pueden usarse en cualquier colección.
Select, from, where, group by, join, etc.
Sentencias para ordenamiento de datos.
![Page 6: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/6.jpg)
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;
![Page 7: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/7.jpg)
SENTENCIAS PARA ORDENAMIENTO
static IEnumerable<Estudiante> CrearEstudiantes(){ return new List<Estudiante> { 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;
![Page 8: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/8.jpg)
![Page 9: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/9.jpg)
Posee una API para XML sencilla y rápida.
Facilita el trabajo con documentos XML, tanto de entrada como de salida.
![Page 10: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/10.jpg)
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;
![Page 11: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/11.jpg)
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)));
![Page 12: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/12.jpg)
![Page 13: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/13.jpg)
Mapea una estructura SQL a una clase .NetTraduce 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.
![Page 14: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/14.jpg)
AplicattionAplicattion
DlinqDlinq(ADO.NET)(ADO.NET)
SQLServerSQLServer
from c in from c in db.Customersdb.Customerswhere c.City = where c.City = “London”“London”select select new new {c.Name, {c.Name, c.Phone }c.Phone }
select Name, Phoneselect Name, Phonefrom customersfrom customerswhere city = ‘London’where city = ‘London’
LINQ Query
ObjectsSubmitChanges()
SQL Query Rows SQL or Stores Procedures
Services:Services:• Change trackingChange tracking• Concurrency control Concurrency control • Object identityObject identity
![Page 15: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/15.jpg)
DLINQ Designer
![Page 16: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/16.jpg)
Relaciones entre entidades
private System.Nullable<long> _VEH_KILOMETRAJE;private string _VEH_COMENTARIO;
private EntitySet<VHC_PARTE> _VHC_PARTEs;private EntityRef<VHC_MODELO> _VHC_MODELO;private EntityRef<VHC_PROPIETARIO> _VHC_PROPIETARIO;
![Page 17: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/17.jpg)
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()};
![Page 18: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/18.jpg)
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);
![Page 19: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/19.jpg)
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;
![Page 20: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/20.jpg)
Eliminación
VehiculosDataContext objVeh_DB = new VehiculosDataContext();
objVeh_DB.VHC_VEHICULOs.Remove(objVeh_DB.VHC_VEHICULOs.Single( p => p.VEH_ID == v.VEH_ID));
![Page 21: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/21.jpg)
![Page 22: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/22.jpg)
Soporta las funciones y Stored Procedures.
![Page 23: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/23.jpg)
Reutilización de SPs
objVeh_DB.InsertarMarcas(strNombre, strPais);
objVeh_DB.ActualizarMarcas(intMarId, strNombre, strPais);
![Page 24: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/24.jpg)
![Page 25: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/25.jpg)
http://weblogs.asp.net/scottgu/ msdn2.microsoft.com/netframework/aa904594.aspxwww.microsoft.com/spanish/msdn/articulos/archivo/041206/voices/LINQ_Project.mspxblogs.microsoft.co.il/blogs/bursteg/archive/tags/VS2008/default.aspx
![Page 26: Julián Enrique Verdezoto Celi. Conceptos Generales LINQ en objetosDEMO LINQ y XMLDEMO LINQ y SQLDEMO.](https://reader033.fdocuments.es/reader033/viewer/2022061518/551ceddb550346447a8b51b7/html5/thumbnails/26.jpg)
© 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.