我試圖加入使用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.Nullable1[[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'.
有人可以幫忙。
你能分享一下GridView代碼嗎? –
爲什麼加入?別。你有一個導航屬性PredbiljezbeEF.SeminariEF。 –
我想過了,但我對它並不是很熟悉。你能寫一些例子來說明在這種情況下如何使用它。 –