DataTable dt = PurchaseArriveInfoBus.GetPurchaseArriveInfo(companyCD, txtArriveNo, txtTitle, txtProvider); XElement dsXML = ConvertDataTableToXML(dt); //linq排序 var dsLinq = (order == "ascending") ? (from x in dsXML.Descendants("Data") orderby x.Element(orderBy).Value ascending select new DataSourceModel() { ID = x.Element("ID").Value, ArriveNo = x.Element("ArriveNo").Value, Title = x.Element("Title").Value, ProviderID = x.Element("ProviderName").Value, Purchaser = x.Element("Purchaser").Value, ProductNo = x.Element("ProductNo").Value, ProductName = x.Element("ProductName").Value, ColorName = x.Element("ColorName").Value, TotalPrice = x.Element("TotalPrice").Value, ProductCount = x.Element("ProductCount").Value, InCount = x.Element("InCount").Value, DetailID = x.Element("DetailID").Value, UnitName = x.Element("UnitName").Value, JiBenCount = x.Element("JiBenCount").Value, UnitPrice = IsDisplayPrice ? x.Element("UnitPrice").Value : "0.000000" }) : (from x in dsXML.Descendants("Data") orderby x.Element(orderBy).Value descending select new DataSourceModel() { ID = x.Element("ID").Value, ArriveNo = x.Element("ArriveNo").Value, Title = x.Element("Title").Value, ProviderID = x.Element("ProviderName").Value, Purchaser = x.Element("Purchaser").Value, ProductNo = x.Element("ProductNo").Value, ProductName = x.Element("ProductName").Value, ColorName = x.Element("ColorName").Value, TotalPrice = x.Element("TotalPrice").Value, ProductCount = x.Element("ProductCount").Value, InCount = x.Element("InCount").Value, DetailID = x.Element("DetailID").Value, UnitName = x.Element("UnitName").Value, JiBenCount = x.Element("JiBenCount").Value, UnitPrice = IsDisplayPrice ? x.Element("UnitPrice").Value : "0.000000" }); int totalCount = dsLinq.Count();
dsLinq.Count() 引发了“System.NullReferenceException”类型的异常,其中任何字段都不能为null