1
當我編譯我的節目,我有這樣的錯誤:錯誤時顯示視圖
'System.Collections.Generic.ICollection' does not contain a definition for 'WIE_Ilosc' and no extension method 'WIE_Ilosc' accepting a first argument of type 'System.Collections.Generic.ICollection' could be found (are you missing a using directive or an assembly reference?)
我必須在我的代碼改變什麼,使其正常工作?
我的觀點:
@model List<Webb.Models.Faktury>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Faktura VAT</h2>
<p>
Oryginal</p>
<table width="100%">
<tr>
<td>ID</td>
<td>Data S.</td>
<td>Numer</td>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.FAK_Id</td>
<td>@item.FAK_DataS</td>
<td>@item.Firma.FIR_Rachunek</td>
<td>@item.Wierszes.WIE_Ilosc</td>
</tr>
}
</table>
</body>
</html>
我的控制器:模型的
public ActionResult Reports(int? id)
{
// Setup sample model
var pro = (from a in db.Fakturies
join b in db.Wierszes on a.FAK_Id equals b.WIE_Fkid
join c in db.Produkties on b.WIE_Pid equals c.PRO_Id
select a);
pro = pro.Where(a => a.FAK_Id == id);
if (Request.QueryString["format"] == "pdf")
return new PdfResult(pro.ToList(), "Reports");
return View(pro);
}
部分:
public Faktury()
{
this.Wierszes = new HashSet<Wiersze>();
}
.
.
.
.
public virtual ICollection<Wiersze> Wierszes { get; set; }
public virtual Firma Firma { get; set; }
public virtual Klienci Klienci { get; set; }
public virtual Statusy Statusy { get; set; }
}
由於Wierszes沒有在LINQ查詢預計不會'item.Wierszes'總是空 –
Faktury有這個'Wierszes'屬性和延遲加載可能給他的數據。有一段時間沒有使用EF了:) – Shyju