实体框架“未来查询”的NHibernate等价物 [英] NHibernate equivalent of Entity Framework "Future Queries"

查看:71
本文介绍了实体框架“未来查询”的NHibernate等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实体框架的扩展名为未来查询,允许批量查询查询,

There is an extension to Entity Framework called Future Queries that allows queries to be batched up and processed at the same time.

例如,从他们的文档中:

For example, from their docs:

// build up queries
var q1 = db.Users
    .Where(t => t.EmailAddress == "one@test.com")
    .Future();

var q2 = db.Tasks
    .Where(t => t.Summary == "Test")
    .Future();

// this triggers the loading of all the future queries
var users = q1.ToList();

NHibernate中有任何等效项,还是可能提供此类功能的扩展?

Is there any equivalent in NHibernate, or an extension that might give this type of functionality?

推荐答案

是的,有一个这样的功能。最好的,如果你读:

Yes, there is a such feature. Best if you'll read:

小号:


NHibernate 2.1中的新功能是 Future< T>() FutureValue< T>()函数。它们本质上是将查询执行延迟到更晚的时间,NHibernate此时将会有更多关于应用程序应该做什么的信息,并相应地进行优化。这基于NHibernate的现有功能,多重查询,但是这样做的方式很容易使用,几乎是无缝的。

One of the nicest new features in NHibernate 2.1 is the Future<T>() and FutureValue<T>() functions. They essentially function as a way to defer query execution to a later date, at which point NHibernate will have more information about what the application is supposed to do, and optimize for it accordingly. This build on an existing feature of NHibernate, Multi Queries, but does so in a way that is easy to use and almost seamless.

这个文章的一些例子:

using (var s = sf.OpenSession())
using (var tx = s.BeginTransaction())
{
    var blogs = s.CreateCriteria<Blog>()
        .SetMaxResults(30)
        .Future<Blog>();
    var countOfBlogs = s.CreateCriteria<Blog>()
        .SetProjection(Projections.Count(Projections.Id()))
        .FutureValue<int>();

    Console.WriteLine("Number of blogs: {0}", countOfBlogs.Value);
    foreach (var blog in blogs)
    {
        Console.WriteLine(blog.Title);
    }

    tx.Commit();
}

这篇关于实体框架“未来查询”的NHibernate等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆