Bob
Bob

Reputation: 4386

How to loop within a Linq to XML statement

How how can I do this:

XDocument xDocument = new XDocument(new XElement("SqlInstall",
            new XElement("Catalogs",
                    new XElement("Install"),
                    foreach (var item in packagedProduct.Installs)
                    {
                            new XElement("File ")..
                    }

                    ))));

It complains about the foreach loop within the Linq statement with "invalid expression term foreach"

Upvotes: 3

Views: 1376

Answers (1)

Draco Ater
Draco Ater

Reputation: 21226

The foreach loop should be rewritten like that:

packagedProduct.Installs.Select( item => new XElement("File ").. );

Upvotes: 7

Related Questions