Normally if would be easier for us if you gave us the requirements. Now you give us code that doesn't work, and ask us to give you code that does work, without telling us what you want.
Anyway, it seems to me that you you have two tables: an FSList
and a sequence of FilmeSerienGenres
.
There seems to be a one-to-many relation between FSList and FilmeSerienGenres: Every FS
from the FSList has zero or FilmeSerienGenres. Every FilmeSerienGenre belongs to exactly one FS, namely the FS that the foreign key refers to.
Every FilmeSerienGenres has a sequence of strings in g.FgGenreNavigation.GBez
.
Requirement: Given a string Txt
, give me from all FS in the FSList, those FS, that have at least one FilmeSerienGenre that has at least one
Filmeg.FgGenreNavigation.GBez that equals TXT.
Or in simple words: FSList is a sequence of Films and Series. Every one of them belongs to zero or more genres: Comedy, Action, Thriller, etc. You can see this in FS.FilmeSerienGenres. You want those Films and Series that have at least one FilmeSerienGenre that matches Txt. I wouldn't be suprised that Filmeg.FgGenreNavigation.GBez
is something like Thriller, Action, etc.
Your problem is, because every FS has a subList FilmeSerienGenres which each have a sublist genre.Filmeg.FgGenreNavigation.GBez.
Whenever you have a "list of sublists", and you want to concatenate them all into one big list, consider to use one of the overloads of Queryable.SelectMany
string txt = ...
var matchingFilmsAndSeries = FSList
.Where(fs => fs.FilmeSerienGenres
.SelectMany(genre => genre.Filmeg.FgGenreNavigation.GBez)
.Contains(txt));
In words: from every fs in FSList, make one big sequence of all Filmeg.FgGenreNavigation.GBez that are in all its FilmeSerienGenres.
The result is a sequence of strings. If this big sequence has at least one value equal to txt
, then keep the FS. If txt is not in the sequence, don't keep the FS.