Skip to content

Instantly share code, notes, and snippets.

@robashton
Created February 14, 2013 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robashton/4951315 to your computer and use it in GitHub Desktop.
Save robashton/4951315 to your computer and use it in GitHub Desktop.
I'm quite pleased with this new feature
var ordersForCustomer = session.Query<Order>()
.Where(order => order.CustomerId == "customers/bob")
.TransformWith<OrderWithProductInformation, OrderWithProductInformation.Result>()
.List();
public class OrderWithProductInformation : AbstractTransformerCreationTask<Order>
{
public class Result
{
public string OrderId { get; set; }
public string CustomerId { get; set; }
public ResultProduct[] Products { get; set; }
}
public class ResultProduct
{
public string ProductId { get; set; }
public string ProductName { get; set; }
}
public OrderWithProductInformation()
{
TransformResults = orders => from index in orders
let doc = LoadDocument<Order>(index.Id)
select new
{
OrderId = doc.Id,
Products = from productid in doc.ProductIds
let product = LoadDocument<Product>(productid)
select new
{
ProductId = product.Id,
ProductName = product.Name
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment