We are currently in the process of ripping out fluent nhibernate from our application due to partial trust issues. We are moving to Entity Framework 5.1RC using their fluent API.
We have the following method in our repository, and I'm trying to find out if the same query can be written using Entity Framework? I'm obviously looking for it to be as efficient as possible.
public PagedList<Topic> GetRecentTopics(int pageIndex, int pageSize, int amountToTake)
{
// Get a delayed row count
var rowCount = Session.QueryOver<Topic>()
.Select(Projections.RowCount())
.Cacheable()
.FutureValue<int>();
// Get the topics using an efficient query
var results = Session.QueryOver<Topic>()
.OrderBy(x => x.CreateDate).Desc
.Skip((pageIndex - 1) * pageSize)
.Take(pageSize)
.Cacheable()
.Future<Topic>().ToList();
// We might only want to display the top 100
// but there might not be 100 topics
var total = rowCount.Value;
if (total > amountToTake)
{
total = amountToTake;
}
// Return a paged list
return new PagedList<Topic>(results, pageIndex, pageSize, total);
}
Any help/pointers greatly appreciated.