2016-09-21 255 views
0

我試圖加入使用LINQ連接兩個表

在這裏,在實體框架的兩個表的實體框架是型號:

public partial class PredbiljezbeEF 
    { 
     public int idPredbiljezba { get; set; } 
     public Nullable<System.DateTime> datumPredbiljezba { get; set; } 
     public string imePolaznik { get; set; } 
     public string prezimePolaznik { get; set; } 
     public string gradPolaznik { get; set; } 
     public string adresaPolaznik { get; set; } 
     public Nullable<int> postanskiBrojPolaznik { get; set; } 
     public Nullable<bool> statusPredbiljezba { get; set; } 
     public int idSeminar { get; set; } 

     public virtual SeminariEF SeminariEF { get; set; } 
    } 

     public partial class SeminariEF 
    { 

     public SeminariEF() 
     { 
      this.PredbiljezbeEFs = new HashSet<PredbiljezbeEF>(); 
     } 

     public int idSeminar { get; set; } 
     public string nazivSeminar { get; set; } 
     public string opisSeminar { get; set; } 
     public string datumSeminar { get; set; } 
     public Nullable<bool> statusSeminar { get; set; } 
     public Nullable<int> brojPredbiljezbi { get; set; } 

這裏是LINQ表達式:

 if(!IsPostBack) 
     { 
      SeminariEntities db = new SeminariEntities(); 

      var predB = (from x in db.PredbiljezbeEFs 
         join y in db.SeminariEFs on x.idSeminar equals y.idSeminar 
         select new 
         { 
          id = x.idPredbiljezba, 
          ime = x.imePolaznik, 
          prez = x.prezimePolaznik, 
          datum = x.datumPredbiljezba, 
          grad = x.gradPolaznik, 
          adresa = x.adresaPolaznik, 
          post = x.postanskiBrojPolaznik, 
          status = x.statusPredbiljezba, 
          naziv = y.nazivSeminar, 
          datumS = y.datumSeminar 

         }).ToList(); 







      //var predB = (from x in db.PredbiljezbeEFs select x).ToList(); 

      gvPredbiljezbe.DataSource = predB.ToList(); 
      gvPredbiljezbe.DataBind(); 


     } 

我得到這個錯誤:

DataBinding: '<>f__AnonymousType0 10[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Nullable 1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Nullable 1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Nullable 1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=n...' does not contain a property with the name 'idPredbiljezba'.

有人可以幫忙。

+0

你能分享一下GridView代碼嗎? –

+0

爲什麼加入?別。你有一個導航屬性PredbiljezbeEF.SeminariEF。 –

+0

我想過了,但我對它並不是很熟悉。你能寫一些例子來說明在這種情況下如何使用它。 –

回答

0

從異常message => something(數據網格可能?)正試圖從gvPredbiljezbedataSource但查詢最終投影中不包含這種特性你的項目屬性[idPredbiljezba][id]

希望能與名[idPredbiljezba]訪問屬性,幫助