0
votes

I tried both of this but didn't work? how to do that?

.SelectMany(x => x.SectionEvents).SelectMany(t => t.Section)

.SelectMany(x => x.SectionEvents.SelectMany(t => t.Section))

Error :

The type arguments for method 'System.Linq.Enumerable.SelectMany<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,System.Collections.Generic.IEnumerable<TResult>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

EEvent.List<EEvent>("CalendarPeriodUId", ECalendarPeriod.Current().UId).Value.ToList()
                .SelectMany(x => x.SectionEvents.SelectMany(t => t.Section)).ToFCollection().Bind(ddlSection, "SectionName");
1
The compiler is telling you what to do. - Saeb Amini
Please give a short but complete example. I wouldn't expect you to have to specify the type arguments. - Jon Skeet
is this example that suits you, @Jon Skeet? - Mert
I think we need to see the data type EEvent. i.e. to know what the structure of x is in your initial post and also what x.SectionEvents are - Mick
Not really - that's far from a short but complete example demonstrating the problem, isn't it? In particular, I can't copy, paste, compile and see the problem. If you had provided a good example, no-one would have needed to guess... - Jon Skeet

1 Answers

2
votes

I think you want is to select all Sections from Events through a join table.

public class Event
{
    public ICollection<SectionEvent> SectionEvents { get; set; }
}
public class SectionEvent
{
    public Event Event { get; set; }
    public Section Section { get; set; }
}
public class Section
{
    public ICollection<SectionEvent> SectionEvents { get; set; }
}

If that so, then what you need is SelectMany and Select.

var q = events.SelectMany(e => e.SectionEvents).Select(se => se.Section);