我是 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。在 SQL 中,我们只是在讨论几个连接,但我完全不知道如何在 Raven 中执行此操作。
请您参考如下方法:
瑞安
您可以很容易地获取项目和关联的商家(使用 Include)。但是你的索引没有意义。
你想做什么?
