title: Linq to Entities To Column names
body: <p>I am relatively new to Linq to Entities but I am making good progress. One item I haven’t been able to figure out yet is how to extract the columns names from the database. For example in the code below I would like to replace the constants with the field names from the database. </p>
  
  <p>I haven't been able to get the answers I've seen eleswhere to work.</p>
  
  <p>Any help will be appreciated.</p>
  
  <p>Bob</p>
  
  <pre><code>DataTable dtNPRS = new DataTable();
  
  const string kInitDate = "NPR_Init_Date";
  const string kActive = "Active";
  const string kStatusId = "NPR_Status_Id";
  
  try
  {
      DataRow drNPR;
  
      var nprs = (from n in db.FMCSA_NPR
                  join u in db.FMCSA_USER  on n.CREATED_BY equals u.ID
                  join t in db.LKUP_NPR_TYPE  on  n.NPR_TYPE_ID equals t.ID
                  join s in  db.LKUP_AUDIT_STATUS on  n.NPR_STATUS_ID equals s.ID
                  where n.ROLE_ID == pRoleId &amp;&amp; n.OWNER_ID == pOwnerId
                        &amp;&amp; n.NPR_STATUS_ID == pNPRStatusId &amp;&amp; n.ACTIVE == pActive
                  select n).ToList();
  
      if (nprs.Count() == 0)
         return null;
  
      //  / build the table structure we need
      dtNPRS.Columns.Add(kInitDate, typeof(DateTime));
      dtNPRS.Columns.Add(kActive,typeof(bool));
      dtNPRS.Columns.Add(kStatusId,typeof(Int32));
  
      foreach (var npr in nprs)
      {
         drNPR = dtNPRS.NewRow();
         drNPR[kInitDate] = npr.NPR_INIT_DATE;
         drNPR[kActive] = npr.ACTIVE;
         drNPR[kStatusId] = npr.NPR_STATUS_ID;
         dtNPRS.Rows.Add(drNPR);
      }
  
      return dtNPRS;
  }
  </code></pre>