2016-07-07 5 views
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; } 
    } 

答えて

3

があなたのかみそりのコードでは、この行を見てください。

<td>@item.Wierszes.WIE_Ilosc</td> 

しかし、あなたのクラス定義に従って、FakturyクラスのWierszesプロパティには、コレクション型(ICollection<Wiersze>)です。あなたのビューでは、コレクションのWIE_Iloscプロパティにアクセスしようとしています!

すべてのWierszeを表示したい場合は、それらを再びループしてレンダリングする必要があります。

@foreach (var item in Model) 
{ 
    <tr> 
     <td>@item.FAK_Id</td> 
     <td>@item.FAK_DataS</td> 
     <td> 
      @if(item.Wierszes!=null) 
      { 
       foreach(var v in item.Wierszes) 
       { 
        <span>@v.WIE_Ilosc</span> 
       } 
      } 
     </td> 
    </tr> 
} 
+0

Wierszesは、LINQクエリに投影されていないためには、 'item.Wierszes'は常に –

+0

Fakturyが彼にデータを与えるかもしれない。この' Wierszes'プロパティおよび遅延ロードを持っているヌルではないでしょう。しばらくの間EFを使用していない:) – Shyju

関連する問題