M
Michael Knudsen
Hi all.
I have a problem with a linq query.
I'm working on a timesheet project.
Given the following linq query:
var query = from L in listTimesheetRecord
select new
{
Copy = "",
Posted = L.Posted.ToString(),
ClientName = L.ClientName,
MatterID = L.MatterId,
MatterName = L.MatterName,
Language = L.LanguageId,
TransText = L.TransText,
HourMon = L.HourMonday,
HourTue = L.HourTuesday,
HourWed = L.HourWednesday,
HourThu = L.HourThursday,
HourFri = L.HourFriday,
HourSat = L.HourSaturday,
HourSun = L.HourSunday,
recid = L.RecId
};
query = query.OrderBy(o => o.HourTue).ThenBy(p => p.ClientName).ThenBy(q =>
q.MatterID);
I just descovered that the query doesn't return records in the expected
order.
What I wish for is (in this query): give me all records which have a value
greater than zero and then order the remaining records by ClientName and
MatterID. The current query returnes records sortet by hourTue and then by
ClientName/MatterID
e.g.
0 - company A - xxxx
20 - company A - xxxx
1 - company B - xxxx
2 - company B - xxxx
when the desired sortorder is:
0 - company A - xxxx
1 - company B - xxxx
2 - company B - xxxx
20 - company A - xxxx
I know a dirty solution could be just to remove the Thenby-clause but I may
have a lot of records registered on the same Clientname and matterID. Could
anyone help me out here?!
Thanks.
/Michael
I have a problem with a linq query.
I'm working on a timesheet project.
Given the following linq query:
var query = from L in listTimesheetRecord
select new
{
Copy = "",
Posted = L.Posted.ToString(),
ClientName = L.ClientName,
MatterID = L.MatterId,
MatterName = L.MatterName,
Language = L.LanguageId,
TransText = L.TransText,
HourMon = L.HourMonday,
HourTue = L.HourTuesday,
HourWed = L.HourWednesday,
HourThu = L.HourThursday,
HourFri = L.HourFriday,
HourSat = L.HourSaturday,
HourSun = L.HourSunday,
recid = L.RecId
};
query = query.OrderBy(o => o.HourTue).ThenBy(p => p.ClientName).ThenBy(q =>
q.MatterID);
I just descovered that the query doesn't return records in the expected
order.
What I wish for is (in this query): give me all records which have a value
greater than zero and then order the remaining records by ClientName and
MatterID. The current query returnes records sortet by hourTue and then by
ClientName/MatterID
e.g.
0 - company A - xxxx
20 - company A - xxxx
1 - company B - xxxx
2 - company B - xxxx
when the desired sortorder is:
0 - company A - xxxx
1 - company B - xxxx
2 - company B - xxxx
20 - company A - xxxx
I know a dirty solution could be just to remove the Thenby-clause but I may
have a lot of records registered on the same Clientname and matterID. Could
anyone help me out here?!
Thanks.
/Michael