将IEnumerable <pagedata>转换为Episerver PageDataCollection </pagedata>

时间:2014-02-25 11:16:03

标签: linq ienumerable episerver

我怎样才能将Linq查询返回到Episerver PageDataCollection?我无法在网上找到任何相关信息。

//This becomes IEnumerable<DataPapge> i need it to be PageDataCollection
var  banners = DataFactory.Instance
                          .GetChildren(CurrentPageLink)
                          .Where(child => child.PageTypeName == "SomeName") ;

//BannerCollection becomse null 
PageDataCollection bannerCollection = banners as PageDataCollection;

1 个答案:

答案 0 :(得分:5)

将构造函数与ICollection<PageData>

一起使用
PageDataCollection bannerCollection = new PageDataCollection(banners.ToList());

(见source

或者更好的是其他构造函数采用IEnumerable

PageDataCollection bannerCollection = new PageDataCollection(banners);