Rewrite the code without using NHiberate RRS feed

  • Question

  • I followed a tutorial to create my blog engine. The tutorial use NHiberate to return a list.

    using NHibernate;
    using NHibernate.Criterion;
    using NHibernate.Linq;
    using NHibernate.Transform;
    using System.Collections.Generic;
    using System.Linq;
    namespace JustBlog.Core
        public class BlogRepository: IBlogRepository
            // NHibernate object
            private readonly ISession _session;
            public BlogRepository(ISession session)
                _session = session;
            public IList<Post> Posts(int pageNo, int pageSize)
                var query = _session.Query<Post>()
                            .Where(p => p.Published)
                            .OrderByDescending(p => p.PostedOn)
                            .Skip(pageNo * pageSize)
                            .Fetch(p => p.Category);
                query.FetchMany(p => p.Tags).ToFuture();
                return query.ToFuture().ToList();
            public int TotalPosts()
                return _session.Query<Post>().Where(p => p.Published).Count();

    However I don't have the knowledge of NHiberate, I just use Entity Framework code first.

    How to rewrite the code above?

    • Edited by ardmore Thursday, May 22, 2014 11:42 PM typo
    Thursday, May 22, 2014 6:58 PM