2011-01-05 2 views
1

これは説明するのが難しく、おそらく非常に簡単です。c#Linqは辞書内のリストからレコードを除外します

1)私には辞書があります。 (Variable _output)

2)NotificationWrapperの中にリストがあります。

3)このリストの中には、私が一致させる必要があるいくつかの要件があります。

4)これらの要件が一致する場合、私は辞書からNotificationWrapperを返したいと思います。

var itemsToSend = 
    _output.Where(
     z => z.Value.Details.Where(
      x => DateTime.Now >= x.SendTime && 
      x.Status == SendStatus.NotSent && 
      x.TypeOfNotification == UserPreferences.NotificationSettings.NotificationType.Email 
    ) 
).Select().ToList(); 

だから私は、エントリ自体の内部条件に合致する_outputエントリをしたい:(_output.value)

私はこのような何かを試してみました。だから私はループを介して各エントリ、私はそのエントリのリスト内の値をチェックして送信されたかどうかを確認します。それが送信されていない場合、その_output.value項目を返したいと思います。 itemsToSendには、送信されていない_outputエントリが含まれている必要があります。 (_output.value.xxxの一部の値ではありません)

答えて

5

私はあなたがAny()を探していると思います。

+0

+1あなたが正しいと思います。 –

+0

チャームのように働いた。 – Patrick

+0

"Google Chromeでコンパイルされました"? – Dykam

0

これはなんですか? Google Chromeでコンパイル:)

var itemsToSend = _output 
    .Values 
    .Where(n => n.Details.Any(
     x => DateTime.Now >= x.SendTime && 
     x.Status == SendStatus.NotSent && 
     x.TypeOfNotification == UserPreferences.NotificationSettings.NotificationType.Email)) 
    .ToList(); 

すなわちを

public partial class Form1 : Form 
{ 
    public Number SomeNumber { get; set; } 
    public Form1() 
    { 
     InitializeComponent(); 

     var _output = new Dictionary<int, List<Number>> 
          { 
           { 
            1, new List<Number> 
             { 
              new Number {details = new Number.Details{a = true, b = true, c = true}}, 
              new Number {details = new Number.Details{a = false, b = false, c = false}}, 
              new Number {details = new Number.Details{a = true, b = true, c = false}}, 
              new Number {details = new Number.Details{a = false, b = false, c = false}}, 
              new Number {details = new Number.Details{a = true, b = true, c = true}}, 
             } 
            } 
          }; 

     var itemsToSend = (from kvp in _output 
          from num in kvp.Value 
          where num.details.a && num.details.b && num.details.c 
          select num).ToList(); 
    } 

} 

public class Number 
{ 
    public Details details { get; set; } 
    public class Details 
    { 
     public bool a; 
     public bool b; 
     public bool c; 
    } 
} 
関連する問題