【发布时间】:2011-01-22 09:06:19
【问题描述】:
假设我有以下课程:
Product { ID, Name }
Meta { ID, Object, Key, Value }
Category { ID, Name }
Relation {ID, ChildID, ParentID } (Child = Product, Parent = Category)
还有一些示例数据:
产品:
ID Name
1 Chair
2 Table
元
ID Object Key Value
1 1 Color "Red"
2 1 Size "Large"
3 2 Color "Blue"
4 2 Size "Small"
类别
ID Name
1 Indoor
2 Outdoor
关系
ID ChildID ParentID
1 1 1
2 1 2
3 2 1
我们可以使用 Distinct 和 Group by 来产生以下格式(ProductDetail)
ID=1,
Name=Chair,
Parent=
{
{ ID=1, Name="Indoor" },
{ ID=2, Name="Outdoor" }
},
Properties { Color="Red", Size="Large" }
ID=2,
Name=Table,
Parent=
{
{ ID=1, Name="Indoor"}
},
Properties { Color = "Blue", Size = "Small" }
我们可以通过使用得到第一项的“颜色”值
ProductDetails[0].Properties.Color
任何帮助将不胜感激!
【问题讨论】:
标签: entity-framework c#-4.0 linq-to-entities group-by distinct