LINQ to XML - if, iteracja

0

Załóżmy, że mam fragment LINQ to XML jak poniżej, gdzie tworzę sobie strukturę XML.

  1. W jaki sposób wstawić tu if (uzależnić obecność danego XElement od pewnego warunku)?
  2. Jak wyciągnąć tu iterator (liczbę, którą będę mógł wstawić jako Liczbę porządkową LP)?
                            from invoiceItem in invoice.InvoiceItems select
            
                                new XElement("POZYCJA",
                                                           new XElement("LP", "1"),
                                                           new XElement("TOWAR", 
                                                                                new XElement("KOD", invoiceItem.RemoteSystemServiceCode),
                                                                
                                                                                new XElement("NAZWA", invoiceItem.Description)
                                                           ),

                                                           new XElement("STAWKA_VAT",
                                                                                new XElement("STAWKA", invoiceItem.VATRate),
                                                                                new XElement("FLAGA", "2"),
                                                                                new XElement("ZRODLOWA", 0.00)
                                                           ),
                                                           
                                                           new XElement("WARTOSC_NETTO_WAL", invoiceItem.NetValueAdded ),       
                                                           new XElement("WARTOSC_BRUTTO_WAL", invoiceItem.GrossValueAdded),
                                                           new XElement("ILOSC", invoiceItem.Quantity),
                                                           new XElement("JM", invoiceItem.Units)
                                  )
 

1 użytkowników online, w tym zalogowanych: 0, gości: 1