zoukankan      html  css  js  c++  java
  • 通过LINQ to XML生成 XML

    通过LINQ to XML生成 XML
        XML常常用语在客户机和服务器之间交流数据,或者多层应用程序之间交流。 
        用LINQ to SQL查询数据,再用LINQ to XML吧数据转换为XML. 
        例: 
            ....... 
            AreslabDataContext aresData = new aresData();    //创建DataContext实例 
            XElement aresCustomerOrders = new XElement("customers",    //创建XML片段实例
                          from c in aresData.Customers            //利用LINQ查询数据,DataContext对象的Customers成员作为数据源
                          select new XElement("customer",        //构建select投射
                                          new XAtrribute("ID", c.CustomerID),
                                          new XAtrribute("Company", c.CompanyName), 
                                                  from o in c.orders
                                                  select new XElement("order",
                                                          new XAtrribute("orderID",o,OrderID),
                                                          new XAtrribute("orderTotal", o.Order_Detail.Sum(od=>od.Quantity*od.UnitPrice))
                                          ) //end order
                            )    //end customer
             );    //end customers 
            string xmlFileName = "c:/.../aresCustomerOrders.xml"; 
            aresCustomerOrders.Save(xmlFileName); 
  • 相关阅读:
    3.1 创建模型-实体属性
    3. 创建模型
    2.1 DbContext
    2. EF Core 如何显示执行的SQL语句
    1.1 为现有数据库生成实体模型
    1. EF Core 概述
    【2020-08-01】人生十三信条
    【一句日历】2020年8月
    【2020-07-31】一个像我一样精力充沛的孩子
    【2020-07-30】强大内心是自己的义务
  • 原文地址:https://www.cnblogs.com/zhangtao/p/2347540.html
Copyright © 2011-2022 走看看