0

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.

YodasMyDad
  • 9,248
  • 24
  • 76
  • 121

1 Answers1

2

AFAIK EF does not have query batching see here. You could implement it yourself which is tricky.

Alternativly you could get NH to work under medium trust, information here and here.

In the comments of this link there is a link to NHibernate dlls working under medium trust (i haven't testet myself).

Community
  • 1
  • 1
Firo
  • 30,626
  • 4
  • 55
  • 94
  • Thanks, we have tried everything and fluent nhibernate will not work under medium trust. – YodasMyDad Jul 11 '12 at 14:15
  • is generating xml from FNH and embed it as resource an option? Or serialize the configuration object and use this? – Firo Jul 12 '12 at 06:27
  • Thanks for coming back, we spent days trying all sorts of configurations and instead have just ripped it out and now using EF. – YodasMyDad Jul 12 '12 at 18:34
  • run as part of a build `using (var file = File.Open("NHconfig.serialized", FileMode.Create)) { new BinaryFormatter().Serialize(file, config); }`, deploy the file and loading with `using (var file = File.Open("NHconfig.serialized", FileMode.Open)) { return (Configuration)new BinaryFormatter().Deserialize(file, config); }`. – Firo Jul 12 '12 at 19:55