Following the previous question, I now have a collection of anonymous type
[User: Username (like forename.surname, User ID).
This collection of "users" should ultimately be tied to a drop-down list. This is fine, but I need to do a sort by last name and first name. but this is complicated by the fact that the username format is .surname filename.
At a high level, this will include a Splitline to separate the components name, and then ToTitleCase()both parts, and then store the new values in another object within the list, which I can then sort usingList<T>.OrderBy(...).ThenBy(...)
It occurred to me that all this new syntax that I am trying to learn may include a way to execute this process in a few lines of short code. Can anyone confirm or deny this?
Thank.
EDIT 3:
I think I hacked it:
var salesusers = (
from s in lstReport
group s by new { s.SalesUserId,s.Username}
into g
select new
{
Username = g.Key.Username.Split('.')[1].ToTitleCase() + " " + g.Key.Username.Split('.')[0].ToTitleCase(),
Surname = g.Key.Username.Split('.')[1].ToTitleCase(),
Forename = g.Key.Username.Split('.')[0].ToTitleCase(),
UserId = g.Key.SalesUserId
}
).OrderBy(a=> a.Surname).ThenBy(a=> a.Forename);
I need to create separate first and last name fields from a username for sorting purposes and a username for binding to a drop-down list. It seems crazy, but it works so beautifully that I stick to it for now. Appreciate your comments.
EDIT2:
So I got to that. Now I wonder if the syntax can combine the operation Group bywith my previous question with this step.
var sortedUsers = from u in salesusers
orderby u.UserName.Split('.')[1], u.UserName.Split('.')[0]
select new {UserName = u.UserName.Replace(".", " ").ToTitleCase(), UserId = u.UserId.Value};
Anyone ...?
EDIT: <p > a > , , - , ToTitleCase .
:
var sortedUsers = from u in salesusers
orderby u.UserName.Split('.')[1], u.UserName.Split('.')[0]
select u;
, , , ToTitleCase ing. , , / / , , , ; -)