如 <Weight xsi:type="x:decimal">1.2</Weight >,定义了一个叫做 Weight 的 String 属性,它的值是 1.2。
apple1 的最终外观如下:
同样的方法我们可以添加 apple2
再添加 Pear 类型的 pear1
呵呵,这样就添加完了。如果这个时候我想修改 apple1 呢?只需要在地址栏中输入 https://food.data.database.windows.net/v1/fruit/apple1,点击GET,修改好后再点击PUT即可。(PUT 对应 UPDATE 操作)删除呢?呵,一个硕大的DELETE出现在底部,就不用我说了吧?
接下来我们就可以使用 LINQ 来玩弄它了!
基本语法如下
运算符和布尔操作符
比如,我们现在可以在地址栏中输入 https://food.data.database.windows.net/v1/
在查询框中输入 from e in entities where e.Id=="fruit" select e,点击QUERY。
此时文本框中就会出现 fruit 这个 Container 的内容。简单吧?
让我们循序渐进:
地址栏输入 https://food.data.database.windows.net/v1/fruit
查询框输入 from e in entities where e.Kind=="Apple" select e,点击QUERY,此时文本框中就会展示出 apple1 和 apple2 的内容。
执行查询 from e in entities where e.Kind=="Apple" && e["Color"]=="Red" select e
则只能看到 apple2 的内容,因为只有 apple2 的 "Color" 等于 "Red"
读者走到这里可能有疑问了。为什么是 e.Kind 和 e["Color"] 呢?到底是用 "." 还是用 "[]" 呢?解释一下:对于 Entity 的元数据属性(metadata property),需要使用 ".",如 e.Id, e.Kind;对于普通属性,则使用 "[]",如 e["Color"]。
读者可以继续练习更多:
from e in entities where e.Kind=="Apple" && (e["Color"]!="Red"||e["Color"]!="Blue") select e (使用括号)
from e in entities where e.Kind=="Apple" && (e["Weight"]>=4) select e (使用表达式)
from e in entities where (e["Weight"]>=4) select e(多种Kind的Entity可以混合在一起查询)
from e in entities where e["RecordDate"]>="2008-12-15" select e(使用日期)
from e in entities select e (取得所有Entity)
from e in entities where e.Id>"pea" select e (字符串使用比较符号)
注意:同一个 Kind 的 Entity 可以包含的不同的属性(不推荐)。比如我们可以把 apple1 中的 <Availability /> 属性删除掉,完全没有影响。可以执行以下查询进行测试
from e in entities where e["Availability"]==false && e.Kind=="Apple" select e