1
+----+---------+--------+
| id | animal | type |
+----+---------+--------+
| 0 | dog | TypeA |
| 1 | cat | TypeA |
| 2 | dog | TypeB |
| 3 | cat | TypeB |
+----+---------+--------+
显然我想要的EF使用的GroupBy做这在某种程度上是这样的:集团通过+选择进入新的嵌套类结构
- dbAnimal.GroupBy(X => x.animal );
但是,如果我想furtherly将数据映射到下面的阶级结构是什么?
public class Animal
{
public Animal()
{
this.animalType = new List<Type>();
}
public string animalDesc { get; set; }
public List<Type> animalType { get; set; }
public class Type
{
public string typeDesc { get; set; }
}
}
例JSON格式:
[
{
"animalDesc": "dog",
"animalType":
[
{
"typeDesc": "TypeA",
},
{
"typeDesc": "TypeB",
}
]
},
{
"animalDesc": "cat",
"animalType":
[
{
"typeDesc": "TypeA",
},
{
"typeDesc": "TypeB",
}
]
}
]
我的问题是如何在EF使用的GroupBy后,以实现映射到类模型。
其他解决方法也是受欢迎的。谢谢。
http://stackoverflow.com/questions/847066/group-by-multiple-columns可能的重复 – auburg