Thursday, August 15, 2013

A groupby example in Linq


This is an example of applying a group by on a Name object. I started off grouping by just first name, and decided to add Age and do a group by using multiple fields.

class Name {
 public string FirstName;
 public string LastName;
 public int Age;
}
void Main()
{
 var names = new List{ new Name{ FirstName="Joe", LastName="A", Age=11}, new Name{ FirstName="Joe", LastName="B", Age=11}
  , new Name{ FirstName="Timmy", LastName="Pumpurdink"}, new Name{ FirstName="Timmy", LastName="Doheenee"},  new Name{ FirstName="Timmy", LastName="Doheenee", Age=1}
 };
  
  var grouped = names.GroupBy (n => new {n.FirstName, n.Age}).Select (n => new {Key=n.Key, Count=n.Count(), LastNames=string.Join(", ", n.AsEnumerable().OrderBy (x => x.LastName).Select (x => x.LastName).ToList())}).Dump();
  
}

Here's the result:

Friday, August 09, 2013

As I Grew Older


It was a long time ago.
I have almost forgotten my dream.
But it was there then,
In front of me,
Bright like a sun-

read full poem by Langston Hughes here...

Make linqpad show sql print statement in the console by doing this

Throw this baby on the top of your linqpad code and enjoy print goodness.

((System.Data.SqlClient.SqlConnection)this.Connection).InfoMessage += (object obj, SqlInfoMessageEventArgs e)=>{
    if (e.Message.Length < 200)  string.Format("    TSQL PRINT: {0}", e.Message).Dump();

};

Monday, July 29, 2013

Nice C# Helper Class for working with POST or GET web requests

You need the following namespaces:

System
System.Collections.Generic
System.IO
System.Linq
System.Net
System.Text

The code is here, shared as via LinqPad's instant share feature.

Saturday, July 20, 2013

Nice task management tool

I've been using Google Tasks for a long time but needed something better and am glad I stumbled across Trello. I wanted to use a kanban board style list and collaborate with other people.  Thanks Trello for a great product.