title: How to return first 50 characters of text in LINQ call
body: <p>I have a small winapp that uses LinqToSQL as it's DAL.  I am creating a summary view of all the CaseNotes for a given person and one of the fields is a Details box.  I need to return only the first 50 characters of that column to my treeview function.</p>
  
  <p>Any hints on how I do that?  The below is how my TreeView function gets its data for display  and the ContactDetails is the column in question.</p>
  
  <pre><code>        public static DataTable GetTreeViewCNotes(int personID)
      {
          var context = new MATRIXDataContext();
          var caseNotesTree = from cn in context.tblCaseNotes
                          where cn.PersonID == personID
                          orderby cn.ContactDate
                          select new { cn.CaseNoteID,cn.ContactDate, cn.ParentNote, cn.IsCaseLog, cn.ContactDetails };
  
          var dataTable = caseNotesTree.CopyLinqToDataTable();
          context.Dispose();
          return dataTable;
      }
  </code></pre>
  
  <hr>
  
  <h2>ANSWER</h2>
  
  <p>I am posting this here in case any future searchers wonder what the solution looks like in the questions context.</p>
  
  <pre><code>        public static DataTable GetTreeViewCNotes(int personID)
      {
          DataTable dataTable;
          using (var context = new MATRIXDataContext())
          {
              var caseNotesTree = from cn in context.tblCaseNotes
                                  where cn.PersonID == personID
                                  orderby cn.ContactDate
                                  select new
                                             {
                                                 cn.CaseNoteID,
                                                 cn.ContactDate, 
                                                 cn.ParentNote, 
                                                 cn.IsCaseLog, 
                                                 ContactDetailsPreview = cn.ContactDetails.Substring(0,50)
                                             };
  
              dataTable = caseNotesTree.CopyLinqToDataTable();
          }
          return dataTable;
      }
  </code></pre>