我是Raven的新手,所以我甚至不确定我是否采取了正确的方法。我需要生成一个项目列表,这些项目的属性是从单独的文档中提取的......基本上是一个JOIN。
说我有这些对象:
public class Merchant
{
public string Id {get;set;}
public string MerchantName {get;set;}
}
public class Location
{
public string Id {get;set;}
public string MerchantId {get;set;}
public string City {get;set;}
}
public class Item
{
public string Id {get;set;}
public string MerchantId {get;set;}
public string ItemName {get;set;}
}
我需要将MapReduce(我认为)放入MerchantItem列表
public class MerchantItem
{
public string ItemId {get;set;}
public string MerchantId {get;set;{
public string LocationId {get;set;}
public string ItemName {get;set;}
public string City {get;set;}
public string MerchantName {get;set;}
}
这是我的(非工作)多地图缩小:
AddMap<Merchant>(merchants => from m in merchants
select new
{
ItemId = (string)null,
MerchantId = m.Id,
LocationId = (string)null,
ItemName = (string)null,
City = (string)null,
MerchantName = m.Name
});
AddMap<Location>(locations => from l in locations
select new
{
ItemId = (string)null,
MerchantId = l.MerchantId,
LocationId = l.Id,
ItemName = (string)null,
City = l.City,
MerchantName = (string)null
});
AddMap<Item>(items=> from i in items
select new
{
ItemId = i.Id,
MerchantId = i.MerchantId,
LocationId = (string)null,
ItemName = i.ItemName,
City = (string)null,
MerchantName = (string)null
});
Reduce = results => from r in results
group result by r.LocationId
into g
select new
{
ItemId = g.Select(x => x.ItemId),
MerchantId = g.Select(x => x.MerchantId),
LocationId = g.Key,
ItemName = g.Select(x => x.ItemName ).Where(x => x != null).FirstOrDefault(),
City = g.Select(x => x.City ).Where(x => x != null).FirstOrDefault(),
MerchantName = g.Select(x => x.MerchantName ).Where(x => x != null).FirstOrDefault()
});
我的想法是我需要一个MerchantItem用于数据库中的每个Item和Location。在SQL中,我们只是谈论几个连接,但我完全不知道如何在Raven中这样做。
答案 0 :(得分:0)
瑞恩
您可以轻松地获取商品和相关商家(使用Include
)。但你的索引毫无意义。
你想做什么?