Reputation: 55062
class Foo{
public string FooText { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }
public ICollection<Bar> Bars{ get; set; }
}
class Bar{
public Foo Foo { get; set; }
public Language Language { get; set; }
public string FooText { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }
}
I have a collection of Foo. I want to get Foo and Bar with Language with language Name "English"
fooCollection.Where(x =>
x.Translations.Where(q =>
q.Language.LanguageName == "English"));
and this fails. Can not convert Foo to bool.
How can i get this done. Essentially i want to get Foo and Bar whose Language is english.
Upvotes: 0
Views: 163
Reputation: 3418
x.Translations.Where
returns a collection, not a boolean.
fooCollection.Where(x =>
x.Translations.Where(q =>
q.Language.LanguageName == "English")
.Count() > 0);
should do the trick.
Edit: Added parenthesis due to user2864740 comment. (But I agree that .Any() is the preferred way.)
Upvotes: 4