2014-09-05 86 views
0

我试过这两个,但没有工作?怎么做?SelectMany里面SelectMany

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

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

错误:

的类型参数方法 'System.Linq.Enumerable.SelectMany<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,System.Collections.Generic.IEnumerable<TResult>>)' 不能从使用中推断出来。尝试明确指定类型参数 。

EEvent.List<EEvent>("CalendarPeriodUId", ECalendarPeriod.Current().UId).Value.ToList() 
       .SelectMany(x => x.SectionEvents.SelectMany(t => t.Section)).ToFCollection().Bind(ddlSection, "SectionName"); 
+0

编译器告诉你该怎么做。 – 2014-09-05 06:33:30

+0

请给出一个简短但完整的例子。我不希望你必须指定类型参数。 – 2014-09-05 06:40:49

+0

就是适合你的这个例子@Jon Skeet? – Mert 2014-09-05 06:52:50

回答

2

我想你想通过一个连接表来选择活动的所有部分。

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; } 
} 

如果是这样,那么你需要的是SelectManySelect

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

不错的猜测!!!!! – Mick 2014-09-05 07:00:22

+0

是的,你是对的!第二个SelectMany错了。感谢您的帮助 :) – Mert 2014-09-05 07:00:55