c# - Multi nested FirstOrDefault -
i have following model:
public class stredisko { public string name { get; set; } public observablecollection<substredisko> pracoviska { get; set; } public observablecollection<substredisko> dohodari { get; set; } } public class substredisko { public string name { get; set; } public string code { get; set; } public vyplatnepasky vyplatnapaska { get; set; } public mzdovenaklady mzdovenaklady { get; set; } public poistne poistne { get; set; } }
i trying run super simple linq query should return first element matches following condition:
var sstredisko = strediska.firstordefault( n => n.pracoviska.firstordefault(x=>x.name == "somename"));
i run condition against: observablecollection<stredisko> strediska
however unknown reason (to me) gives me following error: cannot implicitly convert type 'substredisko' 'bool'.
what doing wrong?
you're looking enumerable.any
:
var sstredisko = strediska.firstordefault( n => n.pracoviska.any(x => x.name == "somename"));
firstordefault
yield first element matches predicate. want match against first element , yield bool
indicating match has been found, any
does.
Comments
Post a Comment