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

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.Value.Substring(2, 2) == "03"
    where text != null
    select new Content
    {
        Text = text.Value,
        Title = title.Value
    };
于 2013-06-17T09:05:13.783 に答える
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 に答える
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 に答える