Joseph Michael Pesch
VP Programming

Linq Child/Nested Entity Join to Master Table Entity

by 26. May 2011 10:13
    private void LoadList_AssignedResources(int RequestId)
    {
      using (SPMetalDataContext dc = new SPMetalDataContext(this.Web.Url))
      {

        ResourceRequestsItem req = dc.ResourceRequests
          .Where(x => x.Id.Equals(RequestId)).FirstOrDefault();
        
        var qry = from rs in dc.Resources
                  join rx in req.Resources on rs.Id equals rx.Id
                  select new
                  {
                    Title = rs.Title,
                    Id = rs.Id
                  };

        AssignedResourcesList.DataTextField = "Title";
        AssignedResourcesList.DataValueField = "Id";
        AssignedResourcesList.DataSource = qry;
        AssignedResourcesList.DataBind();
      }
    }

Tags:

C# | LINQ to SQL

Comments are closed