I have this LINQ Query which returns the data shown in the image below:
var result = jmdict
.Where(x => x.Sequence == 1438690)
.SelectMany(entry =>
entry.Senses.Select(s =>
(entry.Sequence, s.Glosses.Where(x => x.Language.Code == "eng"))));
Does anyone have any ideas how I could modify this so that item2 would return just the value of Term ("weather","the elements" etc) instead of the IEnumerator which it currently returns.
1) I tried this suggestion which was given to me earlier
var r3 =
jmdict.Where(x => x.Sequence == 1438690)
.SelectMany(entry => entry.Senses.Select(s => s.Glosses.Where(x => x.Language.Code == "eng")
.Select(y => (entry.Sequence, y => y.Term))));
But this does not work and there's an error line under the last Select giving this error message :
GetDetails.cs(155,155): Error CS0411: The type arguments for method 'Enumerable.Select(IEnumerable, Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly. (CS0411) (Download)
public static List<IJapaneseDictionaryEntry> jmdict;
public class JapaneseDictionaryEntry : IJapaneseDictionaryEntry {
public int Sequence { get; set; }
private readonly List<Sense> senses = new List<Sense>();
public IEnumerable<ISense> Senses => this.senses;
}
public interface ISense {
IEnumerable<Gloss> Glosses { get; }
}
public class Gloss {
public string Term { get; }
public Language Language { get; }
public Gloss(string term, Language language, string gender)
{
this.Term = term;
this.Language = language;
this.Gender = gender;
}
}
.Senses.Select
with.Senses.SelectMany
in the suggested code. You ought to useSelectMany
anytime you need to convert a enumerable of enumerables into a single enumerable. – tukaef