、延迟加载
原来的查询方式如下:
IEnumerable<User> users = session
    .Query<User>()
    .Where(x => x.Name == "john");

延迟加载方式:
Lazy<IEnumerable<User>> lazyUsers = session
    .Query<User>()
    .Where(x => x.Name == "John")
    .Lazily();

IEnumerable<User> users = lazyUsers.Value;

//一次执行所有延迟操作
IEnumerable<User> users = null;
IEnumerable<City> cities = null;

session
    .Query<User>()
    .Where(x => x.Name == "John")
    .Lazily(x => users = x);

session
    .Query<City>()
    .Where(x => x.Name == "New York")
    .Lazily(x => cities = x);

session.Advanced.Eagerly.ExecuteAllPendingLazyOperations();

//lucene的也支持
Lazy<IEnumerable<User>> users = session.Advanced
    .LuceneQuery<User>()
    .WhereEquals("Name", "John")
    .Lazily();

、交集

在服务端进行交集操作,只返回符合全部条件的数据
session.Query<TShirt>("TShirtIndex")
       .Where(x => x.Manufacturer == "Raven")
       .Intersect()
       .Where(x => x.Types.Any(t => t.Color == "Blue" && t.Size == "Small"))
       .Intersect()
       .Where(x => x.Types.Any(t => t.Color == "Gray" && t.Size == "Large"))
       .ToList();

或者这么写
session.Advanced.LuceneQuery<TShirt>("TShirtIndex")
       .Where("Manufacturer:Raven INTERSECT Color:Blue AND Size:Small INTERSECT Color:Gray AND Size:Large")
       .ToList();

、禁止缓存和跟踪
session.Query<User>().Customize(x => x.NoCaching());
session.Query<User>().Customize(x => x.NoTracking());

、动态聚合
假设我们有一条这样的sql语句
 group by Product

linq的写法是:
var result = session.Query<Order>("Orders/All")
                    .Where(x => x.Total > )
                    .AggregateBy(x => x.Product)
                        .SumOn(x => x.Total)
                    .ToList();

store的
store.DatabaseCommands.PutIndex("Orders/All", new IndexDefinitionBuilder<Order>()
{
    Map = orders => from order in orders
                    select new
                    {
                        order.Total,
                        order.Product,
                        order.Concurrency
                    },
    SortOptions = { { x => x.Product, SortOptions.Double } }
});

扩展查询:
result = session.Query<Order>("Orders/All")
                .AggregateBy(x => x.Product)
                .AddRanges(x => x.Total < ,
                           x => x.Total >=  && x.Total < ,
                           x => x.Total >=  && x.Total < ,
                           x => x.Total >= )
                .SumOn(x => x.Total)
                .ToList();

result = session.Query<Order>("Orders/All")
                .AggregateBy(x => x.Product)
                    .SumOn(x => x.Total)
                    .CountOn(x => x.Total)
                .AndAggregateOn(x => x.Concurrency)
                    .MinOn(x => x.Total)
                .ToList();

result = session.Query<Order>("Orders/All")
                .AggregateBy(x => x.Product)
                    .SumOn(x => x.Total)
                    .CountOn(x => x.Total)
                .AndAggregateOn(x => x.Concurrency)
                    .MinOn(x => x.Total)
                .ToList();
05-02 00:21