Question

I got this tblDocument table which has a one to many relationship to a couple of other tables. I have created this querystring that displays the content of the document. In this soulution i only display the DocPerson id. What im trying to do is to display the name of the person which is located in the tblPerson table. Can someone help me?

    if (!IsPostBack)
    {
        string strId = Request.QueryString["id"];
        int id;
        if (int.TryParse(strId, out id))
        {
            var db = new MyModelContext();
            var p = db.tblDocuments.SingleOrDefault(x => x.DocId == id);
            if (p != null)
            {

                lblCaseNr.Text = p.DocNr;
                lblPerson.Text = p.DocPerson.ToString();
                lblCourt.Text = p.DocCourt.ToString();
                lblYear.Text = p.Docyear.ToString();
                lblResume.Text = p.DocResume;
                lblResult.Text = p.DocResult;
                lblLaw.Text = p.DocLaw.ToString();

            }
        }
    }
}
Was it helpful?

Solution

For your LINQ expression, try the following:

var q = from d in db.tblDocuments join p in db.tblPerson 
          on d.DocId equals p.DocId
          where d.DocId == id
          select new {d.DocId, p.DocPerson}

If you need to access other fields, simply add them to your select new clause.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top