Custom List of Entries

Sep 28, 2009 at 9:03 PM

I am using blogengine to power a news section inside of a custom app.    I need to be able to return the UNION of two category lists.

In my code, I have the following working:

 

List<IPublishable> myPosts = new List<IPublishable>();

Category INTLcat = Category.Categories.Find(x => x.Title == "General");
Guid categoryId = new Guid(INTLcat.Id.ToString());
myPosts = Post.GetPostsByCategory(categoryId).ConvertAll(new Converter<Post, IPublishable>(delegate(Post p) { return p as IPublishable; }));

However if I use the same code structure and grab a List<IPublishable> set for another Category, I receive conversion errors when I try the following:

 

myPosts = myPosts.Union(mySecondCategory);

 

The errors I receive are:

 

Error 43 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<BlogEngine.Core.IPublishable>' to 'System.Collections.Generic.List<BlogEngine.Core.IPublishable>'. An explicit conversion exists (are you missing a cast?) C:\Users\Andy.Garrett\Documents\Subversion Projects\myathletesinactionorg\web\Default.aspx.cs 63 31 C:\...\web\

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<BlogEngine.Core.IPublishable>' to 'System.Collections.Generic.List<BlogEngine.Core.IPublishable>'. An explicit conversion exists (are you missing a cast?)

Any suggestions?
Thanks.

 

 

 

Sep 29, 2009 at 3:34 AM

hi,

just a quick answer, (maybe something i got wrong)

two way about for avoid cast error

1) with existed codes,with last conversion like below


            myPosts = myPosts.Union(myotherPosts).Select(p=> (IPublishable) p).ToList();


2) or without union below ( i didn't really test)

 List<IPublishable> myunionPosts = new List<IPublishable>();
myunionPosts = Post.Posts.Where(p => p.Categories.Contains(INTLcat) || p.Categories.Contains(othercategory)).Select(p1 => (IPublishable)p1).ToList()

 

best regards,

Sep 29, 2009 at 2:11 PM

the first solution worked great!   Thanks for the help