c# - LINQ: Aggregate Rows based on dictionary or mapping? -


i firing q linq query against sp list employees involved, how many items belong them , overall percentage.

i pointed error within data: on several rows 3 users not listed "lastname, firstname" domain\username. need inconsistencies in data flattened out.

one possibility ignore results name contains "domain\". i'd map 3 usernames real names.

   domain\user1 => lastname, firstname    domain\user2 => lastname, firstname    domain\user3 => lastname, firstname 

and aggregate result "lastname, firstname" row of user

my actual code looks this:

public ienumerable<employeevm> getallemployees()     {         entitylist<ticketselement> tickets = _db.getlist<ticketselement>("tickets");         return tickets.where(b => b.bearbeiterid != null && b.bearbeiterimnname != string.empty && b.bearbeiterimnname != null)                       .groupby(b => b.bearbeiterimnname)                       .orderbydescending(b => b.count())                       .select(b => new employeevm() { name = b.key, val = b.count() });      } 

what best way map 3 users , aggregate corresponding results?

kind regards

/edit: have made slight progress. have edited groupby reflect 1 user.

.groupby(b => new { b.bearbeiterimnname, bearbeitername = b.bearbeiterimnname == @"domain\user1" ? "lastname, firstname" : b.bearbeiterimnname  }) 

this returns user twice in list, means need find way aggregate rows same username.

you can try introduce conditional statement in select this:

.select(b => new employeevm() { name = !b.key.contains("domain") ? b.key : new statement,  val = b.count() }); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -