mostlylucid

scott galloway's personal blog...
posts - 911, comments - 723, trackbacks - 11

My Links

News

Archives

Post Categories

Misc. Coding

Voodoo coding

I've been playing around with the new .NET 3.5 features including the as yet unreleased MVC framework (well, the version I'm playing with...). As I've said before I never really had the chance to use this stuff much when it first came out...but it's phenomenal! The code below provides paging of blog entries straight from my blog DB. I am still blown away by how simple this is to do now and just how little code I needed to write. Interesting times (and not in the nasty 'chinese proverb' sense of the word :-)) lay ahead for me!
public class PostModel
    {
       private static PostsDataContext pdc = new PostsDataContext();
        public static Posts GetPosts(int blogId,int? page, int? pageSize)
        {
            int skip = page ?? 0 * pageSize ?? 20;
            var posts = (from p in pdc.subtext_Contents where p.BlogId==blogId && p.PostType==1 orderby p.DateAdded descending select p).Skip(skip).Take(pageSize ?? 20);
            Posts postList = new Posts();
            foreach (var post in posts)
            {
                postList.Add(new Post { Id = post.ID, Title = post.Title, Body = post.Text });
            }
            return postList;
        }
    }

Print | posted on Wednesday, February 27, 2008 10:31 PM |

Comments have been closed on this topic.

Powered by: