I have the below LINQ method which gets called from a User Control
and dumped straight to a standard DataGridView
. My users want it default sorted, first, by DisenrollmentDate
and then, Member Name
. Right now, with the code below, it sorts by DisenrollmentDate
ONLY.
BLLCmo.cs
public static DataTable GetAllMembers(Guid workerID)
{
var AllEnrollees = from enrollment in context.tblCMOEnrollments
where enrollment.CMOSocialWorkerID == workerID || enrollment.CMONurseID == workerID
join supportWorker in context.tblSupportWorkers on enrollment.EconomicSupportWorkerID equals supportWorker.SupportWorkerID into workerGroup
from worker in workerGroup.DefaultIfEmpty()
orderby enrollment.DisenrollmentDate ascending
select new
{
enrollment.ClientID,
MemberName = BLLConnect.MemberName(enrollment.ClientID),
NurseName = BLLAspnetdb.NurseName(enrollment.CMONurseID),
SocialWorkerName =BLLAspnetdb.SocialWorkerName(enrollment.CMOSocialWorkerID),
enrollment.DisenrollmentDate,
enrollment.EnrollmentDate,
ESFirstName = worker.FirstName,
ESLastName = worker.LastName,
ESPhone = worker.Phone
};
var dataTable = AllEnrollees.CopyLinqToDataTable();
return dataTable;
}
BLLConnect.cs
public static String MemberName(Int32 personID)
{
var memberName = from person in context.tblPersons
where person.PersonID == personID
orderby person.LastName ascending
select person.FirstName + " " + person.LastName;
return memberName.SingleOrDefault();
}