0

我们目前在剥开从我们的应用程序功能NHibernate的过程中,由于部分信任的问题。我们正在使用流利的API转向Entity Framework 5.1RC。NHibernate的查询等效实体框架查询

我们已经在我们的资料库下面的方法,我试图如果相同的查询可以使用实体框架编写找出?我显然希望它尽可能高效。

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); 
    } 

任何帮助/指针非常感谢。

回答

2

AFAIK EF没有查询配料see here。你可以implement it yourself这是棘手的。

另外,您可以获得NH在中等信任下工作,信息herehere

this link的意见有NHibernate的DLL文件在中等信任(我还没有testet自己)工作的链接。

+0

谢谢,我们已经尝试了一切,流利的nhibernate不会在中等信任下工作。 – leen3o 2012-07-11 14:15:48

+0

正在从FNH生成xml并将其嵌入为资源选项?或者序列化配置对象并使用它? – Firo 2012-07-12 06:27:53

+0

感谢您回来,我们花了好几天的时间尝试各种配置,而只是将其翻出来,现在使用EF。 – leen3o 2012-07-12 18:34:02