从列表中使用LINQ SELECT并使用WHERE

时间:2019-04-22 18:53:35

标签: c# linq

如何正确编写此LINQ语句?我有课程“排课”的列表(排课)。它无需WHERE子句即可工作。当我添加WHERE时,它将引发NullReferenceException。

string xml = @"<soapenv:Envelope 
              xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" 
              xmlns:soap=""http://soap.inf.hexing.cn"">
              <soapenv:Header/>
              <soapenv:Body>
              <soap:doCommand>
             <!--Optional:-->
            <arg0><![CDATA[<?xml version=""1.0"" encoding=""UTF-8""?>
           <RequestMessage xmlns=""http://iec.ch/TC57/2011/schema/message""
           xmlns:m=""http://iec.ch/TC57/2011/MeterReadSchedule#"" 
           xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
           xsi:schemaLocation=""http://iec.ch/TC57/2011/schema/message Message.xsd"">
          <Header>
          <Verb>create</Verb>
          <Noun>MeterReadSchedule</Noun>
          <Revision>2.0</Revision>
          <Timestamp>" + timestamp + @"</Timestamp>
          <Source>Hesco</Source>
          <AsyncReplyFlag>false</AsyncReplyFlag>
          <ReplyAddress>" + hexURL + @"</ReplyAddress>
          <AckRequired>false</AckRequired>
          <User>
          <UserID>" + hexUID + @"</UserID>
         </User>
         <MessageID>String</MessageID>
         <CorrelationID>String</CorrelationID>
         <Property>
         <Name>password</Name>
         <Value>" + hexPWD + @"</Value>
         </Property>
         <Property>
         <Name>timeout(h)</Name>
         <Value>8</Value>
         </Property>
         </Header>
         <Payload>
         <m:MeterReadSchedule>";


         foreach (var x in ID)
        {
            xml+=@"<m:EndDevice>
            <m:mRID></m:mRID>
            <Names>
              <name>" + x.ToString() + @"</name>
            </Names>
            </m:EndDevice>";
        }


        xml+= @"<m:ReadingType>
        <m:Names>
          <m:name>MonthlyBilling</m:name>
          <m:NameType>
            <m:name>BillingType</m:name>
          </m:NameType>
        </m:Names>
        </m:ReadingType>
        <m:TimeSchedule>
        <m:recurrencePeriod>86400</m:recurrencePeriod>
        <m:scheduleInterval>
          <m:end>" + endTime + @"</m:end>
          <m:start>" + startTime + @"</m:start>
        </m:scheduleInterval>
        </m:TimeSchedule>
        </m:MeterReadSchedule>
        </Payload>
        </RequestMessage>]]></arg0>
        </soap:doCommand>
        </soapenv:Body>
        </soapenv:Envelope>";

0 个答案:

没有答案