문제

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();

            }
        }
    }
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top