LINQ : Reading the XML file using LINQ to XML and Visual Basic 9.0 syntax

Reading the XML file using LINQ to XML and Visual Basic 9.0 syntax

Imports <xmlns:o="http://schemas.devleap.com/Orders">
' ...
Dim xmlOrders As XDocument = XDocument.Load("Orders.xml")
Dim orders = _
From o In xmlOrders.<o:orders>.<o:order> _
Select New Order With {
.CustomerID = o.@idCustomer, _
.Product = New Product With {
.IdProduct = o.@idProduct,
.Price = o.@price}, _
.Quantity = o.@quantity}


The result of these LINQ to XML queries could be used to transparently load a list of Order entities into a customer Orders property, using LINQ to SQL to submit the changes into
the physical database layer:

customer.Orders.AddRange(
From o In xmlOrders.<o:orders>.<o:order> _
Where o.@idCustomer = customer.CustomerID _
Select New Order With {
.CustomerID = o.@idCustomer, _
.Product = New Product With {
.IdProduct = o.@idProduct,
.Price = o.@price}, _
.Quantity = o.@quantity})

No comments:

Post a Comment