マイカートクラス
public class Cart
{
[Key]
public int CartID { get; set; }
[Required]
public int BillID { get; set; }
[Required]
[ForeignKey("BillID")]
public virtual Bill Bill { get; set; }
public virtual ICollection<CartItems> Products {get; set;}
}
私の CartItems クラス
public class CartItems
{
[Key]
public int CartItemID { get; set; }
[Required]
public int ProductId { get; set; }
[ForeignKey("ProductId")]
public Product Product { get; set; }
[Required]
public int Qunatity { get; set; }
}
内部リピーターを設定するための私のクエリは次のようになります。
List<AdminCartItems> items = (from c in context.Carts
where c.Bill.Date == currentDate
select new AdminCartItems
{
Products = c.Products,
BillNo = c.Bill.BillNumber,
Orderer = c.Bill.Name + ", " + c.Bill.Adress + ", " + c.Bill.PostalCode + " " + c.Bill.Country,
Sum = c.Products.Sum(x => x.Qunatity * x.Product.Price)
}).ToList();
CartRepeater.DataSource = items;
this.DataBind();
public class AdminCartItems
{
public ICollection<CartItems> Products {get; set;}
public int BillNo {get; set;}
public string Orderer {get; set; }
public double Sum {get; set;}
}
aspx ページは次のようになります。
<asp:Repeater ID="CartRepeater" runat="server">
<ItemTemplate>
<p><b>Broj računa: </b><%# Eval("BillNo")%></p>
<p><b>Naručioc: </b><%# Eval("Orderer")%></p>
<br />
<table class="table">
<tr>
<th><center><b>Slika</b></center></th>
<th><center><b>Proizvod</b></center></th>
<th><center><b>Količina</b></center></th>
<th><center><b>Cena</b></center></th>
<th><center><b>Ukupno</b></center></th>
</tr>
<asp:Repeater ID="ItemRepeater" runat="server" DataSource='<%# Eval("Products") %>' >
<ItemTemplate>
<tr>
<td>
<center><img src="/DBImages/<%# Eval("Product.Image") %>.png" class="productImage"/></center>
</td>
<td style="text-align:right">
<center><p><b>Proizvođač: </b><%# Eval("Product.Manufacturer.Name")%></p></center>
<center><p><b>Naziv: </b><%# DataBinder.Eval(Container.DataItem, "ProductID" %></p></center>
</td>
<td style="text-align:right">
<center><p><%# Eval("Qunatity")%></p></center>
</td>
<td style="text-align:right">
<center><p><%# Eval("Product.Price")%></p></center>
</td>
<td style="text-align:right">
<%--<center><p><%# Eval("Qunatity")%></p></center>--%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<b style="float: right; font-size:larger; margin-right: 30px;">
Svega: <%# Eval("Sum")%> RSD
</b>
<br />
<hr />
</ItemTemplate>
</asp:Repeater>
私の問題は次のとおりです。製品オブジェクトの属性を内部リピーターに表示するにはどうすればよいですか。
私の製品オブジェクトは次のようになります。
public class Product
{
[Key]
public int ProductID { get; set; }
[Required]
public string Name { get; set; }
[Required]
public double Price { get; set; }
[Required]
public string Quantity { get; set; }
public string Description { get; set; }
[Required]
public bool OnSale { get; set; }
public double SalePrecent { get; set; }
[Required]
public int Image { get; set; }
[Required]
public int Stock { get; set; }
[Required]
public int CategoryID { get; set; }
[ForeignKey("CategoryID")]
public virtual Category Category { get; set; }
[Required]
public int ManufacturerID { get; set; }
[ForeignKey("ManufacturerID")]
public virtual Manufacturer Manufacturer { get; set; }
}