+----+---------+--------+
| id | animal | type |
+----+---------+--------+
| 0 | dog | TypeA |
| 1 | cat | TypeA |
| 2 | dog | TypeB |
| 3 | cat | TypeB |
+----+---------+--------+
Obviously what I want to do is using GroupBy in EF which somehow like this:
- dbAnimal.GroupBy(x => x.animal);
But what if I want to furtherly map the data into the below class structure?
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; }
}
}
Example in JSON format:
[
{
"animalDesc": "dog",
"animalType":
[
{
"typeDesc": "TypeA",
},
{
"typeDesc": "TypeB",
}
]
},
{
"animalDesc": "cat",
"animalType":
[
{
"typeDesc": "TypeA",
},
{
"typeDesc": "TypeB",
}
]
}
]
My question is how to achieve the mapping to class model after using GroupBy in EF.
Other workaround are also welcome too. Thanks.