ich folgendes haben:Wie eine Liste zu einem DTO kartieren, wo eine Eigenschaft eine Zeichenfolge und die andere Eigenschaft ist, ist meine Quelle Liste
class Product
{
int Id;
string Name;
}
class ProductDTO
{
int Id;
string Val;
}
class LookupDTO
{
string Name;
IEnumerable<ProductDTO> options;
}
Ich habe eine Liste von Product
und ich muss auf Karte in die LookupDTO
wo Name = "myList"
und options = myProducts
var myProducts = new List<Product>();
myProducts (new Product { Id = 1, Name = "Apple" });
myProducts (new Product { Id = 2, Name = "Banana" });
myProducts (new Product { Id = 3, Name = "Pear" });
ich möchte dies in LookupDTO
zur Karte folgendes zu erzeugen:
LookupDTO
Name: "myList"
options: [ { id:1, val:"1 - Apple" }, { id:2, val:"2 - Banana" }, { id:3, val:"3 - Pear" } }
Wie kann ich das, was ich habe, in diesem Formular abbilden?