0

我有以下内容:

var result =
    from entry in feed.Descendants(a + "entry")
    let content = entry.Element(a + "content")
    let properties = content.Element(m + "properties")
    let text = properties.Element(d + "Text")
    let title = properties.Element(d + "Title")
    let partitionKey = properties.Element(d + "PartitionKey")
    select new Content
    {
        Text = text.Value,
        Title = title.Value
    };

我想做的是添加一个位置,以便只有一些项目被放入结果中。如何添加条件:

partitionKey.Substring(2, 2) == "03" && text != null

选择?

4

5 回答 5

2

代替

where partitionKey.Substring(2, 2) == "03" && text != null

利用

where partitionKey.Value.Substring(2, 2) == "03" && text != null

partitionKey 是 XElement 类型,当您需要它的值时。

于 2013-06-17T09:12:05.190 回答
2

只需在选择之前添加条件:

var result =
    from entry in feed.Descendants(a + "entry")
    let content = entry.Element(a + "content")
    let properties = content.Element(m + "properties")
    let text = properties.Element(d + "Text")
    let title = properties.Element(d + "Title")
    let partitionKey = properties.Element(d + "PartitionKey")
    where partitionKey.Value.Substring(2, 2) == "03"
    where text != null
    select new Content
    {
        Text = text.Value,
        Title = title.Value
    };
于 2013-06-17T09:05:13.783 回答
1
        var result =
from entry in feed.Descendants(a + "entry")
let content = entry.Element(a + "content")
let properties = content.Element(m + "properties")
let text = properties.Element(d + "Text")
let title = properties.Element(d + "Title")
let partitionKey = properties.Element(d + "PartitionKey")
where partitionKey.Value.Substring(2, 2) == "03" && text != null
select new Content
{
    Text = text.Value,
    Title = title.Value
};
于 2013-06-17T09:08:54.133 回答
1

在:where之前指定select

var result =
    from entry in feed.Descendants(a + "entry")
    let content = entry.Element(a + "content")
    let properties = content.Element(m + "properties")
    let text = properties.Element(d + "Text")
    let title = properties.Element(d + "Title")
    let partitionKey = properties.Element(d + "PartitionKey")
    where partitionKey.Substring(2, 2) == "03" && text != null
    select new Content
    {
        Text = text.Value,
        Title = title.Value
    };
于 2013-06-17T09:04:52.203 回答
0

我建议使用将 SQL 脚本转换为 LINQ 的 linquer 软件,在 Inner Joins 和更复杂的查询时想象一下?

访问:www.sqltolinq.com/

这是一个非常方便的工具!

于 2013-06-17T09:06:19.640 回答