Ich versuche ein Geschäft in C# zu machen, die in diesem Moment diese Tabellen zusammen:Erhalten Eigenschaft von einer anderen Klasse C#
-Produkten (id, name, ab, Bilder) -Bilder (id, Name, Pfad, product_id)
die wichtigste Klasse ist das Produkt, dessen Felder sind:
public class Product
{
//Id of product
public int Id { get; set; }
//Ref of product
public string Ref{ get; set; }
//prize
public double Prize{ get; set; }
//Name
public string NameProd{ get; set; }
//Descr of product
public string DescProduct { get; set; }
//Iva of product
public IVA Iva { get; set; }
//Stock of the product
public int Stock{ get; set; }
//Category of product
public Category Category { get; set; }
//Images of the product
public List<Imgs> Images { get; set; }
}
Wie Sie sehen können, die Bilder sind eine Liste der Klasse Bild, bestehend aus:
//Id of image
public int ID { get; set; }
//Name of Img
public string NameImg { get; set; }
//Path of Img
public string PathImg { get; set; }
//FK product table
[ForeignKey("Product")]
public int Product_Id { get; set; }
//Product
public Product Product { get; set; }
Das Problem ist, wenn ich bin die Bilder des entsprechenden Produkts zu nehmen versuchen, die eine Methode in einer anderen Klasse hat, um alle Daten aus der Datenbank übernimmt, wird das Verfahren besteht aus:
public IQueryable<T> GetAll() {
return Context.Set<T>();
}
und ich versuche, alle Daten in einem shop.aspx.cs zu nehmen, mit diesem System:
protected void Page_Load(object sender, EventArgs e)
{
context = new ApplicationDbContext();
productManager = new ProductManager(context);
var products = productManager.GetAll().Include(i => i.Images);
foreach (var product in products)
{
var headRow = new TableHeaderRow();
var row = new TableRow();
headRow.Cells.Add(new TableCell { Text = product.NameProd});
row.Cells.Add(new TableCell { Text = product.Category.ToString() });
row.Cells.Add(new TableCell { Text = "<img src='"+ product.Images.Select(i => i.PathImg).ToList() +"'/>" });
tbody.Controls.Add(headRow);
tbody.Controls.Add(row);
}
}
Aber es nicht funktioniert, und ich bin absolut stucked bekommen. Jede Hilfe ist zu dieser Zeit so hilfreich ... Vielen Dank im Voraus !!
Erarbeiten Sie auf "Aber es funktioniert nicht"? Was funktioniert nicht? Welchen Fehler bekommst du, wenn überhaupt? –
Ein Problem ist, dass jedes Produkt mit einer Liste von Bildern verbunden ist. Aber Ihr Code: row.Cells.Add (new TableCell {Text = " "}); Wo Sie alle Bilder ziehen und versuchen, nur eine anzuzeigen. – DaniDev
Sorry, meine Schuld David, das Problem war, dass meine "Idee" eine Liste, nicht den Pfad des Bildes, aber danke für die Unterstützung – user3342948