i am trying to join two tables in entity framework using LINQ
Here are the models:
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; }
And here is the LINQ expression:
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();
}
i am getting this error:
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]], m scorlib, Version=4.0.0.0, Culture=n...' does not contain a property with the name 'idPredbiljezba'.
Can someone please help.
From the exception message => something
(Data Grid may be?) is trying to access property with name [idPredbiljezba]
from your gvPredbiljezbe
dataSource
but the query final projection doesn't contain such property you project property [idPredbiljezba]
as [id]
hope that helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.