开发者

Dynamic LINQ Unions possible?

开发者 https://www.devze.com 2023-03-26 01:24 出处:网络
Is it possible to dynamically ad开发者_C百科d UNION clauses in LINQ? I have a list of RssFeed collections that I want to aggregate but the number of feeds is not known ahead of time. But I would like

Is it possible to dynamically ad开发者_C百科d UNION clauses in LINQ? I have a list of RssFeed collections that I want to aggregate but the number of feeds is not known ahead of time. But I would like to be able to union them all and take the most recent 10 posts from the bunch.

I guess I could just do a foreach iteration of each feed query and manually add the results to a "master" collection which I could then query by date, but is that the best way?

Ideally I would like to do something like

foreach(RssFeed in myFeeds)
{
  // compose a linq query for the current feed and union it with 
  // the results of the last iteration
}


Like this:

var query = Enumerable.Empty<Something>();

foreach(RssFeed in myFeeds) {
    query = query.Union(something);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号