[英]How can I get totals for more than one column in a list and put this into an object using LINQ?
[英]How can I select using LINQ for an entry that contains a LIST with more than one row?
我有一個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; }
}
我在這樣做LINQ查詢:
var a = entries.SelectMany(x => x.Kanjis)
.Select(x => new { x.Text, x.Priorities });
有沒有辦法可以過濾這個,所以我只檢索至少有一個優先級的條目?
你可以使用Eumerable.Where
:
var a = entries.SelectMany(x => x.Kanjis)
.Where(x => x.Priorities.Any())
.Select(x => new { x.Text, x.Priorities });
或者在查詢語法中:
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.