は、私は製品の特性をreperesent PropertyValuesエンティティを持っています。 私は次の結果を達成しようとしています - プロパティに応じてコレクションを分割する。値が別の場所である場合スプリットコレクションLINQのエンティティフレームワーク
Dictionary<Property, Dictionary<int, string>> dict = new Dictionary<Property, Dictionary<int, string>>()
{
new KeyValuePair<Property, Dictionary<int, string>>()
{
{
Property.Color,
new KeyValuePair<int, string>()
{
{ 5, "white" }, // ProperyValueId, Value
{ 6, "green"}
}
}
}
}
私はGroupByとSelectManyを見ていましたが、方法が見つかりませんでした。今私は、次のしているために :
var query = await db.PropertyValues
.OrderBy(prop => prop.PropertyId)
.Where(prop => prop.PropertyId == Property.Brand)
.ToDictionaryAsync(prop => prop.PropertyValueId, prop => prop.Value);
Dictionary<Property, Dictionary<int, string>> properties = new Dictionary<Property, Dictionary<int, string>>();
properties.Add(Property.Brand, query);
は、JSONを返す必要があります。しかし、まずシーケンスを取得する必要があります。 JSONは次のようになります。
[{
{"colors": [{"5", "Black"}, {"7", "White"}]},
{"brands": [{"78", "Q&Q"}, {"24", "Adidas"}]},
}]
あなたは、結果として期待していることの少しテキスト(表)のrepresantationを提供していただけますか? – sam
編集を参照して、私はどのようにjsonを見る必要が追加されました。 – unsafePtr
答えをご覧ください – sam