Ich habe diese DatentabelleConvert Datatable zu baumartiger Klassenstruktur
Name Amount Category
sample 100.00 1
sample 100.00 1
aasdas 11.00 1
asd 1.00 2
sadjas 1.00 2
sadjas 1.00 2
asdasd 1.00 3
asdasd 1.00 3
test 10.00 3
Und ich habe diese Klasse
public class ProductListModel
{
public string CategoryName { get; set; }
public List<ProductModel> prodList { get; set; }
}
und jede Instanz dieser Klasse enthalten mit dieser Definition eine Liste von Produktmodellen
public class ProductModel
{
public string Name{ get; set; }
public double Amount { get; set; }
}
Wie kann ich diese Datentabelle konvertieren, um auf die Definition vonzu passenKlasse?
So würde die Ausgabe in dieser Form (für die Visualisierung nur):
// Group by category 1
-- ProductListModel
--CategoryName = 1
-- ProdList
-- Name = sample, amount = 100.00
-- Name = sample, amount = 100.00
-- Name = aasdas, amount = 11.00
// Group by category 2
-- ProductListModel
--CategoryName = 2
-- ProdList
-- Name = asd, amount = 1.00
-- Name = sadjas, amount = 1.00
-- Name = sadjas, amount = 1.00
// Group by category 3
-- ProductListModel
--CategoryName = 3
-- ProdList
-- Name = asdasd, amount = 1.00
-- Name = asdasd, amount = 1.00
Ich habe versucht, aber ich bin fest: P
das ist was ich suche! Vielen Dank – Sherlock