I have a little winapp that uses LinqToSQL as a DAL. I am creating a summary overview of all CaseNotes for this person, and one of the fields is the Details window. I need to return only the first 50 characters of this column in my treeview function.
Any hints on how I do this? The following shows how my TreeView function gets its data to display, and ContactDetails is a column.
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; }
ANSWER
I post it here if future search engines are wondering what the solution looks like in the context of the questions.
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; }
c # winforms linq-to-sql
Refracted paladin
source share