简体   繁体   English

如何使用LINQ为包含多行LIST的条目选择?

[英]How can I select using LINQ for an entry that contains a LIST with more than one row?

I have a List of IJapaneseDictionaryEntry objects: 我有一个IJapaneseDictionaryEntry对象列表:

public interface IJapaneseDictionaryEntry
{
    int Sequence { get; }
    IEnumerable<IKanji> Kanjis { get; }
    IEnumerable<IReading> Readings { get; }
    IEnumerable<ISense> Senses { get; }
}

public interface IKanji
{
    string Text { get; }
    IEnumerable<KanjiInformation> Informations { get; }
    IEnumerable<Priority> Priorities { get; }
}

Which I am do a LINQ query on like this: 我在这样做LINQ查询:

var a = entries.SelectMany(x => x.Kanjis)
               .Select(x => new { x.Text, x.Priorities });

Is there a way that I can filter this so I only retrieve entries that have at least one priority? 有没有办法可以过滤这个,所以我只检索至少有一个优先级的条目?

You can use Eumerable.Where : 你可以使用Eumerable.Where

var a = entries.SelectMany(x => x.Kanjis)
               .Where(x => x.Priorities.Any())
               .Select(x => new { x.Text, x.Priorities });

Or in query syntax: 或者在查询语法中:

var e =
    from entry in entries
    from kanji in entry.Kanjis
    where kanji.Priorities.Any()
    select new { kanji.Text, kanji.Priorities };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM