Wednesday, May 27, 2009

list<> sort or order using limbda expression

If doing an in-place sort (i.e. the list is updated):
people.Sort((x, y) => string.Compare(x.LastName, y.LastName));

If need to create a new list:
var newList = people.OrderBy(x=>x.LastName)

Springboard example, sorting sections on section No.

List
sections = new List
();
//... load sections ...
sections.Sort((x, y) => x.SectionNo.CompareTo(y.SectionNo));

insert from selecting from another database

In one case, I need to import data from one database to another database, and I've figured out the format should be

insert into server.newdatabase.owner.table
from select * from server.olddatabase.owner.table

the key point here is the four parts name follows the pattern server.database.owner.object