8

So what I'm doing is using an xml document to determine the order in which certain SQL scripts need to be ran by a database update.

The XML follows this format

<ScriptRules>
    <Database databaseName = “string”>
        <Folder folderPath = “string” executeAllFiles = boolean>
            <file order=”first or last”>“Filename”</file>
        </Folder>
    </Database>
</ScriptRules>

So the class that executes all of the sql files on the database looks at this at changes it's connection and executes files from folders depending on what the config file has told it to do.

Now my question is this:

Let's say that I have a Document that has 4 Database nodes, and each of them have n number of Folder nodes inside with an assortment of file nodes inside of that.

Is it logical of me to assume that if inside of a For Each loop over the Database nodes that I have retrieved into a XElement using database.Elements("Database") that they will be pulled in the order that they appear in the xml file? (same for the file nodes)

As far as I have been able to tell this is the case but I just wanted to verify before I start using this on production databases.

2 Answers 2

10

Yes, Elements returns the elements in document order. From the docs, in the "return value":

An IEnumerable<T> of XElement containing the children of the XContainer that have a matching XName, in document order.

1
  • 1
    do you have a 'Someone asked a question about linq' sense?
    – msarchet
    Jul 20, 2010 at 14:35
3

Yes, so long as you don't use PLINQ, and even then you can ask it to give you the elements in order.

 var orderedCities = (from city in cities.AsParallel().AsOrdered()
                                 where city.Population > 10000
                                 select city)
                                .Take(1000);

http://msdn.microsoft.com/en-us/library/dd460677.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.