就是命令从读出的XDocument项目,通过LINQ的,有保障? [英] Is Order of items read from a XDocument, by LINQ, Guaranteed?

查看:106
本文介绍了就是命令从读出的XDocument项目,通过LINQ的,有保障?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在做什么是使用XML文档,以确定哪些特定的SQL脚本需要由数据库更新跑出的顺序。

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.

该XML的格式如下

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

这样执行所有的 SQL的类数据库上的文件着眼于这个在改变它的连接,然后从文件夹根据什么配置文件告诉它执行文件做的。

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:

让我们说,我有一个文件,有4 数据库节点,和他们每个人都有 N 若干文件夹文件节点内,一个分类里面的节点。

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.

时我是合乎逻辑的假设是,如果在对于每个遍历数据库节点,我已经检索到的XElement 使用 database.Elements(数据库),他们将在订单中拉他们出现在XML文件? (相同文件的节点)

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.

推荐答案

元素返回文档顺序的元素。从的文档,在返回值:

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

这是的IEnumerable&LT; T&GT; 的XElement 的   载有孩子    XContainer 具有匹配的XName ,   在文档顺序。

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

这篇关于就是命令从读出的XDocument项目,通过LINQ的,有保障?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆