How to do a cross join / cartesian product in RavenDB?

倾然丶 夕夏残阳落幕 提交于 2019-12-06 08:13:51

Here is how you can do this with all the empty locations as well:

AddMap<InventoryItem>(inventoryItems =>
    from inventoryItem in inventoryItems
    select new
    {
        LocationName = inventoryItem.Location.Name,
        Items = new[]{
            {
                ItemTypeName = inventoryItem.ItemType.Name,
                Count = 1}
            }
    });
)

this.AddMap<Location>(locations=>
    from location in locations
    select new
    {
        LocationName = location.Name,
        Items = new object[0]
    });


this.Reduce = results => 
    from result in results
    group result by result.LocationName into g
    select new
    {
        LocationName = g.Key,
        Items = from item in g.SelectMany(x=>x.Items)
                group item by item.ItemTypeName into gi
                select new
                {
                    ItemTypeName = gi.Key,
                    Count = gi.Sum(x=>x.Count)
                }

    };
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!