Linq to xaml
声明方法前要加上下面的声明,目前是猜测。
[Category("Grouping Operators")]
[Description("This sample uses group by to partition a list of products by category.")]
语法:toarray创建数组,tolist创建泛型集合。
var customerList = (
from e in XDocument.Load("customers.xml").
Root.Elements("customer")
select new Customer
{
CustomerID = (string)e.Element("id"),
CompanyName = (string)e.Element("name"),
Address = (string)e.Element("address"),
City = (string)e.Element("city"),
Region = (string)e.Element("region"),
PostalCode = (string)e.Element("postalcode"),
Country = (string)e.Element("country"),
Phone = (string)e.Element("phone"),
Fax = (string)e.Element("fax"),
Orders = (
from o in e.Elements("orders").Elements("order")
select new Order
{
OrderID = (int)o.Element("id"),
OrderDate = (DateTime)o.Element("orderdate"),
Total = (decimal)o.Element("total")
})
.ToArray()
}
).ToList();