1
我有下一個實體:C#LINQ加入三甲之列,以嵌套的字典
public class product
{
public string ID {get;set;}
public string Code { get; set; }
}
public class subProduct
{
public string Code { get; set; }
public string productID { get; set; }
}
public class AddValueForSubProduct
{
public string subProductCode { get; set; }
public string AddValue { get; set; }
}
,我想從這個集都Dictionary<string*, Dictionary<string**,string***>>
:
List<product> products = GetProducts();
List<subProduct> subProducts = GetSubProducts() ;
List<AddValueForSubProduct> vForSubProd = GetAddValueForSubProduct();
其中:
Dictionary<string*, Dictionary<string**,string***>>
* product.Code
** subProduct.Code
*** AddValueForSubProduct.AddValue
我想,但我已經收到關於字典中重複鍵的異常。
var res = from p in products
join sb in subProducts on p.ID equals sb.productID into sbs
from c in sbs
join vF in vForSubProd on c.code equals vF.subProductCode into addingData
select new KeyValuePair<string, Dictionary<string, string>>(p.code, addingData.
ToDictionary(v => v.subProductCode, v => v.AddValue));