Friday, November 30, 2007

LINQ Tips

Composite Key

I was looking for the syntax for a composite key join. I could only find it for 3 tables that were chained to gether by mutiple columns. Here's the join syntax for two tables that have 2 columns in column:

var vResult =

from t1 in table1

join t2 in table2 on
new {t1.Key1, t1.Key2} equals

new{t2.Key1, t2.Key2}

select
new {t1.Column3, t2.Column4};

Interesting Syntax

I also found the syntax for a "shaped" return of data. Here's some pseudo:

var vResult =

from t1 in table1

join t2 in table2 join t1.Key1 equals t2.Key1 into Shape

select {t1.Key1, Shape};


I hope these help someone, as I was looking around for a little bit to find these simple nuggets of truth.

No comments: